-
Notifications
You must be signed in to change notification settings - Fork 2
/
arrrrrBot.py
73 lines (63 loc) · 1.78 KB
/
arrrrrBot.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# encoding=utf-8
from config import CHATROOM_PRESENCE
from errbot import BotPlugin, botcmd
from errbot.utils import get_sender_username
class ArrrrrBot(BotPlugin):
@botcmd
def slap(self, mess, args):
"""Let the bot slap people in the chatroom in an piratelike manner"""
return "{0} slaps {1} around a bit with a large trout.".format(get_sender_username(mess), args)
@botcmd
def peek(self, mess, args):
"""Print a saved one-liner"""
argss = args.split(' ', 1)
if argss[0] in self:
return self[argss[0]]
else:
return "Nope."
@botcmd
def p(self, mess, args):
"""Short alias for !peek"""
return self.peek(mess, args)
@botcmd
def rm(self, mess, args):
"""Alias for removing something from the one-liner memory"""
argss = args.split(' ')
for i in range(0, len(argss)):
self.poke(mess, argss[i])
return "...Done."
@botcmd
def poke(self, mess, args):
"""Save a one-liner : !poke name content"""
argss = args.split(' ', 1)
name = argss[0]
if len(argss) == 1:
if name in self:
del self[name]
else:
return "Nope."
else:
content = argss[1]
if len(content) > 80 or '\n' in content:
return "Nope."
else:
self[name] = content
return "Got it."
@botcmd
def peekpoke(self, mess, args):
"""List all saved one-liners (private message only)"""
result = ""
for name in self.keys():
result += "{0}: \t {1}\n".format(name, self[name])
return result
@botcmd(admin_only=True)
def hiersprichtgott(self, mess, args):
self.send(CHATROOM_PRESENCE[0], args, message_type='groupchat')
def callback_message(self, conn, mess):
firstword = mess.getBody()
try:
firstword = firstword[:firstword.index(' ')]
except ValueError:
pass
if firstword in self:
self.send(mess.getFrom(), self[firstword], message_type=mess.getType())