fix channel joining
This commit is contained in:
parent
80a61da9a0
commit
73945d8ec2
41
tracer.py
41
tracer.py
|
@ -13,6 +13,7 @@ import random
|
||||||
|
|
||||||
DB = {}
|
DB = {}
|
||||||
|
|
||||||
|
|
||||||
def grammar(rules):
|
def grammar(rules):
|
||||||
try:
|
try:
|
||||||
res = tracery.Grammar(rules)
|
res = tracery.Grammar(rules)
|
||||||
|
@ -21,6 +22,7 @@ def grammar(rules):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
def load_rules(path):
|
def load_rules(path):
|
||||||
try:
|
try:
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
|
@ -28,6 +30,7 @@ def load_rules(path):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
def populate():
|
def populate():
|
||||||
global DB
|
global DB
|
||||||
DB = {}
|
DB = {}
|
||||||
|
@ -43,9 +46,11 @@ def populate():
|
||||||
else:
|
else:
|
||||||
DB[name] = [grammar(load_rules(rule))]
|
DB[name] = [grammar(load_rules(rule))]
|
||||||
|
|
||||||
|
|
||||||
populate()
|
populate()
|
||||||
print(DB)
|
print(DB)
|
||||||
|
|
||||||
|
|
||||||
def generate(rule):
|
def generate(rule):
|
||||||
populate()
|
populate()
|
||||||
if rule in DB:
|
if rule in DB:
|
||||||
|
@ -59,10 +64,11 @@ def listify(col):
|
||||||
else:
|
else:
|
||||||
return [col]
|
return [col]
|
||||||
|
|
||||||
|
|
||||||
def shuffle(col):
|
def shuffle(col):
|
||||||
a = random.choice(col.keys())
|
a = random.choice(col.keys())
|
||||||
b = random.choice(col.keys())
|
b = random.choice(col.keys())
|
||||||
if 'origin' in [a,b]:
|
if "origin" in [a, b]:
|
||||||
print("origin discard")
|
print("origin discard")
|
||||||
return col
|
return col
|
||||||
temp = col[a]
|
temp = col[a]
|
||||||
|
@ -70,6 +76,7 @@ def shuffle(col):
|
||||||
col[b] = temp
|
col[b] = temp
|
||||||
return col
|
return col
|
||||||
|
|
||||||
|
|
||||||
def fuse(argv):
|
def fuse(argv):
|
||||||
populate()
|
populate()
|
||||||
raw = {}
|
raw = {}
|
||||||
|
@ -93,25 +100,19 @@ if len(sys.argv) > 1:
|
||||||
channels.append("#" + c)
|
channels.append("#" + c)
|
||||||
botnick = "tracer"
|
botnick = "tracer"
|
||||||
|
|
||||||
|
|
||||||
def rawsend(msg):
|
def rawsend(msg):
|
||||||
print(msg)
|
print(msg)
|
||||||
ircsock.send(f"{msg}\r\n".encode())
|
ircsock.send(f"{msg}\r\n".encode())
|
||||||
|
|
||||||
def joinchan(chan):
|
|
||||||
rawsend(f"JOIN {chan}")
|
|
||||||
|
|
||||||
def sendmsg(chan, msg):
|
def send(chan, msg):
|
||||||
# This is the send message function, it simply sends messages to the channel.
|
# This is the send message function, it simply sends messages to the channel.
|
||||||
rawsend(f"PRIVMSG {chan} :{msg}")
|
rawsend(f"PRIVMSG #{chan} :{msg}")
|
||||||
|
|
||||||
# def wexec(msg):
|
|
||||||
# ircsock.send("EXEC -msg "+channel+" "+msg)
|
|
||||||
|
|
||||||
def send(channel, s):
|
|
||||||
sendmsg(f"#{channel}", s)
|
|
||||||
|
|
||||||
def think(chan, nick, msg):
|
def think(chan, nick, msg):
|
||||||
words = re.split('[ \t\s]+', msg)
|
words = re.split("[ \t\s]+", msg)
|
||||||
if len(words) > 0 and nick != "tracer":
|
if len(words) > 0 and nick != "tracer":
|
||||||
if words[0] == "!!list":
|
if words[0] == "!!list":
|
||||||
res = ""
|
res = ""
|
||||||
|
@ -139,28 +140,26 @@ def think(chan, nick, msg):
|
||||||
else:
|
else:
|
||||||
send(chan, res)
|
send(chan, res)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
ircsock.connect((server, 6667)) # Here we connect to the server using port 6667
|
ircsock.connect((server, 6667)) # Here we connect to the server using port 6667
|
||||||
rawsend(f"NICK {botnick}") # here we actually assign the nick to the bot
|
rawsend(f"NICK {botnick}") # here we actually assign the nick to the bot
|
||||||
rawsend(f"USER {botnick} 0 * :tracery bot") # user authentication
|
rawsend(f"USER {botnick} 0 * :tracery bot") # user authentication
|
||||||
|
|
||||||
for c in channels:
|
|
||||||
joinchan(c)
|
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
ircmsg = ircsock.recv(2048)
|
msg = ircsock.recv(2048).decode().split("\r\n")
|
||||||
ircmsg = ircmsg.decode().strip('\n\r')
|
for ircmsg in msg:
|
||||||
print(ircmsg)
|
print(ircmsg)
|
||||||
|
|
||||||
if ircmsg.find("PING") != -1:
|
if "PING" in ircmsg:
|
||||||
rawsend(ircmsg.replace("I", "O"))
|
rawsend(ircmsg.replace("I", "O", 1))
|
||||||
|
|
||||||
if ircmsg.find("001") != -1:
|
if "001" in ircmsg:
|
||||||
for c in channels:
|
for c in channels:
|
||||||
joinchan(c)
|
rawsend(f"JOIN {c}")
|
||||||
|
|
||||||
m = re.match(':(?P<nick>[^ ]+)!.*PRIVMSG #(?P<chan>\w+) :(?P<msg>.*)', ircmsg)
|
m = re.match(":(?P<nick>[^ ]+)!.*PRIVMSG #(?P<chan>\w+) :(?P<msg>.*)", ircmsg)
|
||||||
if m and m.groupdict():
|
if m and m.groupdict():
|
||||||
m = m.groupdict()
|
m = m.groupdict()
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue