-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
133 lines (119 loc) · 4.33 KB
/
bot.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
from irc import *
from carddb import *
import os
import random
channellist = []
server = "irc.uriirc.org"
nickname = "dolchang-bot"
irc = IRC()
irc.connect(server, nickname)
def hssearch(word):
nummode = 0
dscmode = 0
minus = 1
thelist = []
longnamelist = []
if not word:
return "usage: hs [num] <word>"
if word[0:1] == "@ ":
dscmode = 1
word = word[2:]
if word[0] == "-":
minus = -1
if word[1].isnumeric():
word = word[1:]
if word[0:2] == "+ ":
print(len(word))
if len(word) != len("+ 한"):
return "한글 글자 1개만 허용됩니다."
word = word[2:]
for i in range(len(cardnamelist)):
if cardnamelist[i][0:len("한")] == word:
idx = cardnamelist[i].find("(")
longnamelist.append(cardnamelist[i][0:idx].replace(" ","").strip())
if len(longnamelist) == 0:
return word + "(으)로 시작하는 하스스톤 카드는 없습니다."
longnamelist.sort(key = lambda x: len(str(x)),reverse = True)
if len(longnamelist) < 9:
rtvalue = longnamelist[0]
for i in longnamelist[1:]:
rtvalue = rtvalue + ", " + i
return rtvalue
rtvalue = longnamelist[0]
for i in longnamelist[1:9]:
rtvalue = rtvalue + ", " + i
return rtvalue + ",..."
while word and word[0].isnumeric():
nummode = nummode * 10 + int(word[0])
word = word[1:]
word = word.strip()
for i in range(len(cardnamelist)):
if (cardnamelist[i].lower()).find(word.lower()) != -1:
thelist.append(i)
if len(thelist) == 1:
return cardlist[thelist[0]].name + " - " + cardlist[thelist[0]].description
elif len(thelist) == 0:
return "card not found (usage: hs [num] <word>)"
elif nummode > 0:
if len(thelist) < nummode:
nummode = len(thelist)
if minus == -1:
nummode = -nummode
else:
nummode = nummode-1
return cardlist[thelist[nummode]].name + " - " + cardlist[thelist[nummode]].description
elif len(thelist) > 9:
rtvalue = cardnamelist[thelist[0]]
for j in thelist[1:5]:
rtvalue = rtvalue + ", " + cardnamelist[j]
return rtvalue + ", ... (+" + str(len(thelist)-5) + ") 너무 많아요 ㅇㅅㅇ"
else:
rtvalue = cardnamelist[thelist[0]]
for j in thelist[1:]:
rtvalue = rtvalue + ", " + cardnamelist[j]
return rtvalue
def innkeeper():
inntxt = open("innkeeperdb.txt",'r')
idx = random.randrange(50)
for i in range(idx):
ret = inntxt.readline()
return ret
print ("Success")
while 1:
text = irc.get_text()
for channel in channellist:
idx = text.find("PRIVMSG " + channel)
if idx != -1:
msg = text[idx+len("PRIVMSG " + channel + " :"):len(text)]
print (msg)
if msg[0:3] == "hs ":
irc.send(channel, str(hssearch((msg[3:len(msg)]).strip())))
elif msg[0:5] == "echo ":
irc.send(channel, str(msg[5:len(msg)]))
elif msg[0:len("bayoen " + nickname)] == "bayoen " + nickname:
if text[1:text.find("!")] == "I6silver":
irc.quit("bye-bye")
quit()
else:
irc.send(channel, "빠요엔 " + text[1:text.find("!")])
irc.deopping(channel, text[1:text.find("!")])
elif msg[0:5] == "pack ":
pass
elif msg[0:7] == "update ":
if text[1:text.find("!")] == "I6silver" or text[1:text.find("!")] == "hsupdate":
pass
elif "하스스톤" in msg:
irc.send(channel, innkeeper())
idx2 = text.find("INVITE " + nickname)
if idx2 != -1:
msg = text[idx2 + len("INVITE " + nickname + " :"):len(text)]
print (msg)
irc.join(msg)
msg = msg.replace("\r", "").replace("\n","")
if msg not in channellist:
channellist += [msg]
print(channellist)
# idx2 = text.find("JOIN :" + channel)
# if idx2 != -1:
# pmidx = text.find("!")
# irc.opping(channel, text[1:pmidx])