-
Notifications
You must be signed in to change notification settings - Fork 0
/
hhh.py
135 lines (123 loc) · 5.07 KB
/
hhh.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
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
# -*- coding: utf-8 -*-
import weechat
import os.path
import datetime
debug = False
greet = True
userlist = '/home/niels/.weechat/userlist'
users = []
weechat.register('hal', 'The Hell', '6.6.6', 'GPL3', 'Hell Script', '', '')
def get(filename):
file = open(filename, 'r')
users = file.readlines()
file.close()
return users
def put(filename, users):
file = open(filename, 'w')
file.writelines(users)
file.close()
def timer_cb(data, remaining_calls):
current = weechat.current_buffer()
global users
if os.path.isfile(userlist):
weechat.prnt(current, 'HAL\tReading ' + userlist)
users = get(userlist)
else:
weechat.prnt(current, "HAL\tUsing default user list")
users = [
'*!*@82-197-212-247.dsl.cambrium.nl',
'*!*@80-101-145-252.ip.xs4all.nl',
'*!*@2a01:238:4350:ff00:c53e:c819:422a:2511'
]
if debug:
for u in users:
weechat.prnt(current, 'user\t' + u)
weechat.prnt(current, '%s' % data)
return weechat.WEECHAT_RC_OK
weechat.hook_timer(2000, 0, 1, 'timer_cb', 'HAL\tSystem fully operational')
def priv_cb(data, signal, signal_data):
global users
current = weechat.current_buffer()
args = signal_data.split(' ')[0:3]
nick = args[0][1:].split('!')[0]
user = args[0][1:].split('!')[1].split('@')[0]
host = args[0][1:].split('!')[1].split('@')[1]
target = args[2]
message = signal_data.split(' PRIVMSG ')[1].split(' :')[1]
if debug:
weechat.prnt(current, '===\t========== Debug ==========')
weechat.prnt(current, 'raw\t' + signal_data)
weechat.prnt(current, 'vars\tnick=' + nick + ', user=' + user + ', host=' + host + ', target=' + target)
weechat.prnt(current, 'msg\t' + message)
if any(host in u for u in users):
if message[0] == '/':
if len(message.split(' ')) > 1:
arg = message.split(' ')[1]
else:
arg =''
store = False
if message[1:4] == 'say':
weechat.command(current, 'Yo')
weechat.command(current, message[5:])
elif message[1:5] == 'quit':
weechat.command(current, 'hihi')
elif message[1:8] == 'adduser':
if not any(arg in u for u in users):
users.append(arg + '\n')
weechat.prnt(current, 'HAL\t' + arg + ' added')
weechat.command(current, '/msg ' + nick + ' ' + arg + ' added')
else:
weechat.prnt(current, 'HAL\t' + arg + ' already exists')
weechat.command(current, '/msg ' + nick + ' ' + arg + ' already exists')
store = True
elif message[1:8] == 'deluser':
try:
users.remove(arg + '\n')
except:
weechat.prnt(current, 'HAL\tUser does not exist')
weechat.command(current, '/msg ' + nick + ' User does not exist')
else:
weechat.prnt(current, 'HAL\t' + arg + ' deleted')
weechat.command(current, '/msg ' + nick + ' ' + arg + ' deleted')
store = True
elif message[1:10] == 'users':
weechat.command(current, '/msg ' + nick + ' -----begin-----')
for u in users:
weechat.command(current, '/msg ' + nick + ' ' + u)
weechat.command(current, '/msg ' + nick + ' ------end------')
else:
weechat.command(current, message)
if store:
weechat.prnt(current, 'HAL\tStoring ' + userlist)
put(userlist, users)
if debug:
for u in users:
weechat.prnt(current, 'user\t' + u)
if debug:
weechat.prnt(current, 'match\t' + host)
weechat.prnt(current, 'msg\t' + message)
if 'HAL900' in message.upper():
if 'HOE LAAT' in message.upper() or 'TIME' in message.upper():
weechat.command(current, str(datetime.datetime.now()))
return weechat.WEECHAT_RC_OK
weechat.hook_signal('*,irc_in2_privmsg', 'priv_cb', '')
def join_cb(data, signal, signal_data):
server = signal.split(",")[0]
msg = weechat.info_get_hashtable("irc_message_parse", {"message": signal_data})
buffer = weechat.info_get("irc_buffer", "%s,%s" % (server, msg["channel"]))
if buffer:
if debug:
weechat.prnt(buffer, '%s (%s) has joined. Welcome!' % (msg['nick'], msg['host']))
if greet:
weechat.command(buffer, 'для здоровья!')
return weechat.WEECHAT_RC_OK
weechat.hook_signal('*,irc_in2_join', 'join_cb', '')
def mode_cb(data, signal, signal_data):
weechat.prnt('', signal_data)
global users
server = signal.split(",")[0]
msg = weechat.info_get_hashtable("irc_message_parse", {"message": signal_data})
if not any(msg['host'] in u for u in users):
weechat.command('', 'bastard! ' + msg['nick'])
return weechat.WEECHAT_RC_OK
weechat.hook_signal('*,irc_in2_mode', 'mode_cb', '')