Skip to content

Commit

Permalink
Merge pull request #3 from sopel-irc/verb-config
Browse files Browse the repository at this point in the history
Support configuring the list of verbs used for slapping
  • Loading branch information
dgw authored Aug 27, 2024
2 parents 68357b1 + 3f3cae5 commit 7e19b8b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 12 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ _Substitute the appropriate `pip` command based on your environment (e.g.
_If your Sopel configuration requires it, run `sopel-plugins enable slap`,
passing the appropriate config name to `-c` if you have multiple bots._

## Configuration

The easiest way to configure this plugin is via Sopel's built-in wizard:

```sh
sopel-plugins configure slap
```

Right now, there is only one option:

* `verbs`: A list of verbs to choose from when slapping people. Overrides the
default list if set.

Probably, the easiest way to make a custom list is to just press Enter twice
when the config wizard asks for a list of verbs, which will add the default
list to your bot's `.cfg` file. Then you can use your favorite text editor.

_(We're aware that Sopel's wizard doesn't have great UX when it comes to
entering lists. It'll get worked on someday, probably.)_

## Commands

<dl>
Expand Down
37 changes: 37 additions & 0 deletions sopel_slap/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Configuration definitions
Part of `sopel-slap`.
Copyright 2024, dgw, technobabbl.es
https://sopel.chat
"""
from __future__ import annotations

from sopel.config import types

VERBS = (
'annihilates',
'destroys',
'kicks',
'owns',
'punches',
'pwns',
'roundhouse kicks',
'slaps',
)


class SlapSection(types.StaticSection):
verbs = types.ListAttribute('verbs', default=VERBS)


def do_configure(section: types.StaticSection):
section.configure_setting(
'verbs',
"\nEnter verbs to choose from when slapping someone, one per line.\n\n"
"Alternatively, press Enter twice without typing anything to write\n"
"the current list (shown below) to your bot's .cfg file, where it\n"
"can be edited using your favorite text editor.\n\n"
"Current verb list:",
)
10 changes: 10 additions & 0 deletions sopel_slap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@

from sopel import plugin

from .config import SlapSection, do_configure
from .util import slap


def setup(bot):
bot.settings.define_section('slap', SlapSection)


def configure(settings):
settings.define_section('slap', SlapSection)
do_configure(settings.slap)


@plugin.commands('slap', 'slaps')
def slap_command(bot, trigger):
"""Slap a <target> (e.g. nickname)"""
Expand Down
13 changes: 1 addition & 12 deletions sopel_slap/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@
from sopel.bot import SopelWrapper
from sopel.trigger import Trigger

VERBS = (
'annihilates',
'destroys',
'kicks',
'owns',
'punches',
'pwns',
'roundhouse kicks',
'slaps',
)


def slap(bot: SopelWrapper, trigger: Trigger, target: str):
"""Do the slapping."""
Expand Down Expand Up @@ -59,6 +48,6 @@ def slap(bot: SopelWrapper, trigger: Trigger, target: str):
if target in bot.config.core.admins and not trigger.admin:
target = trigger.nick

verb = random.choice(VERBS)
verb = random.choice(bot.settings.slap.verbs)

bot.action(f"{verb} {target}")

0 comments on commit 7e19b8b

Please sign in to comment.