From 1c6801e59e11009f70c39b39ac355ae71dc80ff3 Mon Sep 17 00:00:00 2001 From: dgw Date: Tue, 7 Mar 2023 22:00:00 -0600 Subject: [PATCH] Revamp old slap plugin from extras so it can be installed as a package --- .gitignore | 57 ++++++++++++++++++++++++++++++++++++++ COPYING | 23 ++++++++++++++++ MANIFEST.in | 6 ++++ NEWS | 0 README.md | 34 +++++++++++++++++++++++ setup.cfg | 25 +++++++++++++++++ setup.py | 25 +++++++++++++++++ sopel_slap/__init__.py | 62 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 232 insertions(+) create mode 100644 .gitignore create mode 100644 COPYING create mode 100644 MANIFEST.in create mode 100644 NEWS create mode 100644 README.md create mode 100644 setup.cfg create mode 100755 setup.py create mode 100644 sopel_slap/__init__.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba74660 --- /dev/null +++ b/.gitignore @@ -0,0 +1,57 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..7d1cd07 --- /dev/null +++ b/COPYING @@ -0,0 +1,23 @@ + + Eiffel Forum License, version 2 + + 1. Permission is hereby granted to use, copy, modify and/or + distribute this package, provided that: + * copyright notices are retained unchanged, + * any distribution of this package, whether modified or not, + includes this license text. + 2. Permission is hereby also granted to distribute binary programs + which depend on this package. If the binary program depends on a + modified version of this package, you are encouraged to publicly + release the modified version of this package. + +*********************** + +THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT WARRANTY. ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE TO ANY PARTY FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS PACKAGE. + +*********************** diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..10b886b --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,6 @@ +include NEWS +include COPYING +include README.md + +recursive-exclude * __pycache__ +recursive-exclude * *.py[co] diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..9bdc4c2 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# sopel-slap + +Plugin for Sopel that lets users slap each other in fun ways + +## Installation + +```sh +pip install sopel-slap +``` + +_Substitute the appropriate `pip` command based on your environment (e.g. +`pip3` or `pip3.10` on systems with multiple Python versions available)._ + +_If your Sopel configuration requires it, run `sopel-plugins enable slap`, +passing the appropriate config name to `-c` if you have multiple bots._ + +## Commands + +* **.slap** — Make the bot slap you +* **.slap nickname [reason]** — Slap someone else, with an optional reason + +_If your bot has a non-default `prefix`, substitute it for `.` above._ + +## Credits + +This is based on the original `slap.py` from +[sopel-extras](https://github.com/sopel-irc/sopel-extras) by Michael Yanovich, +dating back to the late '00s/early '10s. It's been rewritten more or less from +scratch to do things in the modern Sopel way. The only meaningful behavior +change was dropping substitution of the caller's nick for `me` and `myself`, +as it's quite possible for a real person to use either of those as a nick and +_no one_\* should be safe from slaps! + +\* — No one except the bot and its admins, that is. diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..adec712 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,25 @@ +[metadata] +name = sopel-slap +version = 0.1.0 +description = Plugin for Sopel that lets users slap each other in fun ways +author = dgw +author_email = dgw@technobabbl.es +url = https://github.com/sopel-irc/sopel-slap +license = Eiffel Forum License, version 2 +classifiers = + Intended Audience :: Developers + Intended Audience :: System Administrators + License :: Eiffel Forum License (EFL) + License :: OSI Approved :: Eiffel Forum License + Topic :: Communications :: Chat :: Internet Relay Chat + +[options] +packages = find: +zip_safe = false +include_package_data = true +install_requires = + sopel>=7.0,<8 + +[options.entry_points] +sopel.plugins = + slap = sopel_slap diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..7590c6d --- /dev/null +++ b/setup.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function +import os +import sys +from setuptools import setup, find_packages + + +if __name__ == '__main__': + print('Sopel does not correctly load plugins installed with setup.py ' + 'directly. Please use "pip install .", or add ' + '{}/sopel_slap to core.extra in your config.' + .format(os.path.dirname(os.path.abspath(__file__))), + file=sys.stderr) + +with open('README.md') as readme_file: + readme = readme_file.read() + +with open('NEWS') as history_file: + history = history_file.read() + + +setup( + long_description=readme + '\n\n' + history, + long_description_content_type='text/markdown', +) diff --git a/sopel_slap/__init__.py b/sopel_slap/__init__.py new file mode 100644 index 0000000..c21e675 --- /dev/null +++ b/sopel_slap/__init__.py @@ -0,0 +1,62 @@ +# coding=utf8 +"""sopel-slap + +Plugin for Sopel that lets users slap each other in fun ways + +Original slap.py copyright 2009, Michael Yanovich, yanovich.net +This rewritten & packaged version for Sopel 7+ copyright 2023, dgw, technobabbl.es + +https://sopel.chat +""" +import random + +from sopel import formatting, plugin, tools + + +VERBS = ( + 'annihilates', + 'destroys', + 'kicks', + 'owns', + 'punches', + 'pwns', + 'roundhouse kicks', + 'slaps', +) + + +@plugin.commands('slap', 'slaps') +def slap(bot, trigger): + """Slap a (e.g. nickname)""" + target = trigger.group(3) + + if target is None: + target = trigger.nick + else: + target = formatting.plain(target) + + if not isinstance(target, tools.Identifier): + # TODO: For Sopel 8.0+ release, switch to new bot.make_identifier() method + # will increase reliability of below "is nick" check + target = tools.Identifier(target) + + if not target.is_nick(): + bot.reply("You can't slap the whole channel!") + return + + if target not in bot.channels[trigger.sender].users: + bot.reply("You can't slap someone who isn't here!") + return + + if target == bot.nick: + if not trigger.admin: + target = trigger.nick + else: + target = 'itself' + + if target in bot.config.core.admins and not trigger.admin: + target = trigger.nick + + verb = random.choice(VERBS) + + bot.action("{} {}".format(verb, target))