-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathircHelpers.py
55 lines (42 loc) · 1.25 KB
/
ircHelpers.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
from core import ircBot
from queue import Queue
from threading import Thread
import time
debug = False
def getNetwork():
return ircBot.network
def getPort():
return ircBot.port
def getChannel():
return ircBot.channel
def getNick():
return ircBot.nickname
def flood_control():
while True:
item = ircBot.q.get()
ircBot.socket.send(item)
time.sleep(1)
ircBot.q.task_done()
def start_queue_thread():
ircBot.q = Queue()
thread = Thread(target=flood_control)
thread.daemon = True
thread.start()
def send(thingToSend):
if debug: print("<< %s" % thingToSend)
ircBot.q.put(thingToSend)
def sayInChannel(thingToSay):
string = 'PRIVMSG %s :%s\r\n' % (getChannel(), thingToSay)
send(string.encode("UTF-8"))
def privateMessage(user, *messages):
for message in messages:
string = 'PRIVMSG %s :%s\r\n' % (user, message)
send(string.encode("UTF-8"))
def pmInChannel(user, message):
string = 'NOTICE %s :%s\r\n' % (user, message)
send(string.encode("UTF-8"))
def callForUsers():
send('NAMES %s\r\n' % getChannel())
def changeNick(newNick):
string = 'NICK %s' % newNick
send(string.encode("UTF-8"))