forked from bigfoot547/bigfootbot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchan.py
59 lines (50 loc) · 1.41 KB
/
chan.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
import bot
class Channel:
def __init__(self, name):
self.name = name
class ChannelManager:
def __init__(self, filename, client):
self.filename = filename
self.client = client
self.channels = []
self.current_channel = 0
try:
file = open(self.filename, 'r')
except FileNotFoundError:
print("[ChannelManager] Input file not found.")
return
str = file.read().split('\n')
print(str)
for each in str:
if len(each) <= 0:
break
self.channels.append(0)
self.channels[self.current_channel] = Channel(each)
self.client.join(each)
self.current_channel += 1
file.close()
def save_chans(self):
file = open(self.filename, 'w')
for each in self.channels:
file.write(each.name + '\n')
file.close()
return 0
def join_chan(self, target):
if self.current_channel > len(self.channels)-1:
self.channels.append(0)
self.channels[self.current_channel] = Channel(target)
self.current_channel += 1
self.client.join(target)
def part_chan(self, number, source):
if number > len(self.channels)-1:
return 1
if len(self.channels) == 1:
self.client.rawmsg('PART', self.channels[number].name, "Bot deactivated by {}.".format(source))
self.channels = []
self.current_channel = 0
return 0
channel = self.channels[number]
self.channels.pop(number)
self.current_channel -= 1
self.client.rawmsg('PART', channel.name, "Bot deactivated by {}.".format(source))
return 0