forked from swee/MeowNex
Update sweebot.py
This commit is contained in:
parent
2f36c10042
commit
36c136dcc3
1 changed files with 47 additions and 42 deletions
89
sweebot.py
89
sweebot.py
|
@ -345,6 +345,48 @@ while True:
|
||||||
#open("log-name-"+channel, "a").write(nick + "\n")
|
#open("log-name-"+channel, "a").write(nick + "\n")
|
||||||
except:
|
except:
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
|
def replased(expression):
|
||||||
|
if channel in logs:
|
||||||
|
try:
|
||||||
|
if expression.split("/")[0].lower() != "s": raise IndexError()
|
||||||
|
find = expression.split("/")[1]
|
||||||
|
replace = expression.split("/")[2]
|
||||||
|
user = None
|
||||||
|
repeat = False
|
||||||
|
index = 1
|
||||||
|
try:
|
||||||
|
extraflags = expression.split("/")[3:]
|
||||||
|
for i in extraflags:
|
||||||
|
if i.lower() == "g":
|
||||||
|
repeat = True
|
||||||
|
elif i.strip().isdigit():
|
||||||
|
print(f"index = {int(i)}")
|
||||||
|
index = int(i)
|
||||||
|
else:
|
||||||
|
print(f"user = {i.lower()}")
|
||||||
|
user = i.lower()
|
||||||
|
except: pass
|
||||||
|
cache = None
|
||||||
|
for i in logs[channel]:
|
||||||
|
if find in i["content"] and (user == None or i["nick"].lower() == user):
|
||||||
|
cache = i
|
||||||
|
break
|
||||||
|
if cache == None:
|
||||||
|
raise Exception("The specified text couldn't be found")
|
||||||
|
else:
|
||||||
|
if repeat:
|
||||||
|
cache["content"] = cache["content"].replace(find, replace)
|
||||||
|
else:
|
||||||
|
cache["content"] = rplce(cache["content"], find, replace, index)
|
||||||
|
cachenick = cache["nick"]
|
||||||
|
cachecontent = cache["content"]
|
||||||
|
multiline(f"[RPL] <{cachenick}> {cachecontent}", channel)
|
||||||
|
except IndexError:
|
||||||
|
irc.send_irc(channel, nick + ": [ERR] Sed expression might be incorrectly written!")
|
||||||
|
except Exception as ex:
|
||||||
|
irc.send_irc(channel, nick + ": [ERR] " + str(ex))
|
||||||
|
else:
|
||||||
|
irc.send_irc(channel, nick + ": [!!!] No logs saved in " + channel)
|
||||||
try:
|
try:
|
||||||
#if True:
|
#if True:
|
||||||
if "PRIVMSG" in text and not nick in my_self:
|
if "PRIVMSG" in text and not nick in my_self:
|
||||||
|
@ -610,47 +652,7 @@ while True:
|
||||||
|
|
||||||
elif command[0] == "$sed":
|
elif command[0] == "$sed":
|
||||||
if len(command) == 2:
|
if len(command) == 2:
|
||||||
if channel in logs:
|
replased(command[1])
|
||||||
try:
|
|
||||||
if command[1].split("/")[0].lower() != "s": raise IndexError()
|
|
||||||
find = command[1].split("/")[1]
|
|
||||||
replace = command[1].split("/")[2]
|
|
||||||
user = None
|
|
||||||
repeat = False
|
|
||||||
index = 1
|
|
||||||
try:
|
|
||||||
extraflags = command[1].split("/")[3:]
|
|
||||||
for i in extraflags:
|
|
||||||
if i.lower() == "g":
|
|
||||||
repeat = True
|
|
||||||
elif i.strip().isdigit():
|
|
||||||
print(f"index = {int(i)}")
|
|
||||||
index = int(i)
|
|
||||||
else:
|
|
||||||
print(f"user = {i.lower()}")
|
|
||||||
user = i.lower()
|
|
||||||
except: pass
|
|
||||||
cache = None
|
|
||||||
for i in logs[channel]:
|
|
||||||
if find in i["content"] and (user == None or i["nick"].lower() == user):
|
|
||||||
cache = i
|
|
||||||
break
|
|
||||||
if cache == None:
|
|
||||||
raise Exception("The specified text couldn't be found")
|
|
||||||
else:
|
|
||||||
if repeat:
|
|
||||||
cache["content"] = cache["content"].replace(find, replace)
|
|
||||||
else:
|
|
||||||
cache["content"] = rplce(cache["content"], find, replace, index)
|
|
||||||
cachenick = cache["nick"]
|
|
||||||
cachecontent = cache["content"]
|
|
||||||
multiline(f"[RPL] <{cachenick}> {cachecontent}", channel)
|
|
||||||
except IndexError:
|
|
||||||
irc.send_irc(channel, nick + ": [ERR] Sed expression might be incorrectly written!")
|
|
||||||
except Exception as ex:
|
|
||||||
irc.send_irc(channel, nick + ": [ERR] " + str(ex))
|
|
||||||
else:
|
|
||||||
irc.send_irc(channel, nick + ": [!!!] No logs saved in " + channel)
|
|
||||||
else:
|
else:
|
||||||
irc.send_irc(channel, nick + ": [???] This command takes only one argument.")
|
irc.send_irc(channel, nick + ": [???] This command takes only one argument.")
|
||||||
|
|
||||||
|
@ -729,8 +731,11 @@ while True:
|
||||||
irc.send_irc(channel, emoticons[command[0]])
|
irc.send_irc(channel, emoticons[command[0]])
|
||||||
elif ":3c" in command:
|
elif ":3c" in command:
|
||||||
if not sbconfig.cflagexist(channel, "-colonthree"):
|
if not sbconfig.cflagexist(channel, "-colonthree"):
|
||||||
multiline(channel, choice(threes))
|
multiline(choice(threes), channel)
|
||||||
|
elif command[0][:2].lower() == "s/"
|
||||||
|
replased(command[0])
|
||||||
# try to parse and find a link
|
# try to parse and find a link
|
||||||
|
|
||||||
if sbconfig.cflagexist(channel, "+links"):
|
if sbconfig.cflagexist(channel, "+links"):
|
||||||
try:
|
try:
|
||||||
for i in command:
|
for i in command:
|
||||||
|
|
Loading…
Reference in a new issue