-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger.py
More file actions
139 lines (115 loc) · 6.87 KB
/
trigger.py
File metadata and controls
139 lines (115 loc) · 6.87 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import time
import sys
import re
import locale
import os
from distutils.util import strtobool
class trigger:
def trigger_notice(self):
if self.hostname == 'NickServ!NickServ@services.' and self.widelands['nickserv']['replay']:
self.update('nickserv', 'replay', False)
self.send_message('NICKSERV: {}'.format(self.content))
def trigger_ctcp(self):
if self.content.find('\x01ACTION') == 0 and re.search('\x01$', self.content, re.IGNORECASE):
self.send_notice('\x01ACTION {}\x01'.format(' '.join(str(i) for i in self.content.replace('\x01', '').split()[1:])), self.user)
if self.content.find('\x01VERSION\x01') == 0:
self.send_notice('\x01VERSION {}:{}:{}\x01'.format(self.widelands['nickserv']['username'], self.version, os.uname()[0]), self.user)
if self.content.find('\x01TIME\x01') == 0:
self.send_notice('\x01TIME {}\x01'.format(time.strftime("%A, %d. %B %Y %H:%M:%S %Z")), self.user)
if self.content.find('\x01USERINFO\x01') == 0:
self.send_notice('\x01USERINFO Ich bin ein automatisch denkendes Wesen, auch bekannt als Bot!\x01', self.user)
if self.content.find('\x01CLIENTINFO\x01') == 0:
self.send_notice('\x01CLIENTINFP ACTION CLIENTINFO FINGER PING SOURCE TIME URL USERINFO VERSION\x01', self.user)
if self.content.find('\x01URL\x01') == 0:
self.send_notice('\x01URL Frag den janus im freenode\x01', self.user)
if self.content.find('\x01SOURCE\x01') == 0:
self.send_notice('\x01SOURCE Frag den janus im freenode\x01', self.user)
if self.content.find('\x01PING') == 0 and re.search('\x01$', self.content, re.IGNORECASE):
if len(self.content.split()) > 1:
self.send_notice('\x01PING {}\x01'.format(' '.join(str(i) for i in self.content.replace('\x01', '').split()[1:])), self.user)
if self.content.find('\x01FINGER\x01') == 0:
self.send_notice('\x01FINGER Du nicht nehmen Kerze! You don\'t take candle!\x01', self.user)
def trigger_admin(self):
content = self.content.split()
if content[1] == 'debug':
if len(content) == 2:
self.send_message("Debug: {}".format("AN" if self.widelands['admin']['debug'] else "AUS"), self.target)
elif len(content) >= 3:
try:
self.update('admin', 'debug', bool(strtobool(content[2])))
self.send_message("Debug: {}".format("AN" if self.widelands['admin']['debug'] else "AUS"), self.target)
except ValueError as Error:
self.send_message("Debug: {}".format(Error))
if content[1] == 'ping':
if len(content) == 2:
self.send_message("PING: {}".format("AN" if self.widelands['ping']['use'] else "AUS"), self.target)
elif len(content) >= 3:
try:
self.update('ping', 'use', bool(strtobool(content[2])))
self.send_message("PING: {}".format("AN" if self.widelands['ping']['use'] else "AUS"), self.target)
except ValueError as Error:
self.send_message("PING: {}".format(Error))
if content[1] == 'channel':
if len(content) == 2:
if len(self.channels) > 0:
self.send_message('Ich bin in {}.'.format(', '.join(self.channels)), self.target)
else:
if content[2] == 'join':
if len(content) == 4 and content[3].startswith('#'):
self.post_string('JOIN {}'.format(content[3]))
self.channels.append(content[3])
self.update('channel', 'liste', self.channels)
if content[2] == 'part':
if len(content) == 4 and content[3].startswith('#'):
if content[3] in self.channels:
self.post_string('PART {}'.format(content[3]))
self.channels.remove(content[3])
self.update('channel', 'liste', self.channels)
else:
self.send_message('{} ist mir nicht bekannt!'.format(content[3]), self.target)
if content[1] == 'event':
if len(content) == 2:
if len(self.events) > 0:
self.send_message('Ich gebe in {} wieder.'.format(', '.join(self.events)), self.target)
else:
self.send_message('Ich gebe in keinem Kanal wieder', self.target)
else:
if content[2] == 'join':
if len(content) == 4 and content[3].startswith('#'):
self.events.append(content[3])
self.update('channel', 'event', self.events)
if content[2] == 'part':
if len(content) == 4 and content[3].startswith('#'):
if content[3] in self.events:
self.events.remove(content[3])
self.update('channel', 'event', self.events)
else:
self.send_message('{} ist mir nicht bekannt!'.format(content[3]), self.target)
def trigger_nickserv(self):
content = self.content.split()
if content[1] == "register":
self.send_message('REGISTER {} {}'.format(self.widelands['nickserv']['password'],
self.widelands['nickserv']['email']), 'NICKSERV')
if content[1] == "verify":
self.send_message('VERIFY REGISTER {} {}'.format(self.widelands['nickserv']['username'],
content[2]), 'NICKSERV')
if content[1] == "identify":
self.send_message('IDENTIFY {} {}'.format(self.widelands['nickserv']['username'],
self.widelands['nickserv']['password']), 'NICKSERV')
if content[1] == "status":
self.update('nickserv', 'replay', True)
self.send_message('STATUS', 'NICKSERV')
def trigger_privmsg(self):
if self.hostname == self.widelands['admin']['hosts']:
if re.search('^nickserv', self.content, re.IGNORECASE):
self.trigger_nickserv()
if re.search('^admin', self.content, re.IGNORECASE):
self.trigger_admin()
if self.content.find('{}hello'.format(self.trigger)) == 0 \
or self.content.find('{}hallo'.format(self.trigger)) == 0 \
or re.search('^hello', self.content, re.IGNORECASE) \
or re.search('^hallo', self.content, re.IGNORECASE):
self.send_message('Hallo {}'.format(self.name), self.target)
if self.content.find('{}ping'.format(self.trigger)) == 0 \
or re.search('^ping {}'.format(self.widelands['nickserv']['username']), self.content, re.IGNORECASE):
self.send_message('pong {}'.format(self.name), self.target)