-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathecho_mentions_example.py
41 lines (35 loc) · 1.74 KB
/
echo_mentions_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Simple functional plugin that shows how to subscribe to an event and
# how to send discord messages.
from nedry.event_types import EventType
from nedry import events
from nedry.plugin import PluginModule
class EchoMentionsExample(PluginModule):
"""
Simple plugin that subscribes to the EventType.DISCORD_BOT_MENTION event,
and whenever a message starting with a bot mention is seen in any public channel
on discord, sends a DM to the author of the message containing whataver text
they typed after the mention.
"""
plugin_name = "Example plugin"
plugin_version = "1.0.0"
plugin_short_description = "Simple example illustrating the plugin system"
plugin_long_description = ""
def _on_mention(self, message, text_without_mention):
# Whenever anybody mentions the bot in a public channel, take the text after
# the mention and echo it back to the same channel the mention was seen on
self.discord_bot.send_message(message.channel, text_without_mention)
def open(self):
"""
Enables plugin operation; subscribe to events and/or initialize things here
"""
# Subscribe to the DISCORD_BOT_MENTION event, which will call our handler
# with the text after the mention, whenever a message starting with a bot
# mention is seen in any public discord channel
events.subscribe(EventType.DISCORD_BOT_MENTION, self._on_mention)
def close(self):
"""
Disables plugin operation; unsubscribe from events and/or tear down things here
"""
# Unsubscribe from the DISCORD_BOT_MENTION event, so that the plugin will
# stop doing its thing if disabled
events.unsubscribe(EventType.DISCORD_BOT_MENTION, self._on_mention)