forked from swee/MeowNex
Update sweebot.py
This commit is contained in:
parent
1d93c75057
commit
34f8e736a1
1 changed files with 50 additions and 7 deletions
55
sweebot.py
55
sweebot.py
|
@ -136,6 +136,11 @@ def humanbytes(B):
|
||||||
return '{0:.2f}GB'.format(B / GB)
|
return '{0:.2f}GB'.format(B / GB)
|
||||||
elif TB <= B:
|
elif TB <= B:
|
||||||
return '{0:.2f}TB'.format(B / TB)
|
return '{0:.2f}TB'.format(B / TB)
|
||||||
|
def rplce(text, old, new, n):
|
||||||
|
parts = text.split(old)
|
||||||
|
if len(parts) <= n:
|
||||||
|
return text # Not enough occurrences to replace
|
||||||
|
return old.join(parts[:n]) + new + old.join(parts[n:])
|
||||||
def replace_color_codes(text):
|
def replace_color_codes(text):
|
||||||
def replacer(match):
|
def replacer(match):
|
||||||
code = match.group(0)
|
code = match.group(0)
|
||||||
|
@ -239,6 +244,7 @@ pats = ["-w-", "Meep...", "Prr!"]
|
||||||
meows_happy = ['Meow!', 'Nyaa~', 'Mrow.', 'Prr! :3', "Mrrp?", "Mreow.", "!woeM", "3: !rrP", "~aayN", "Mew!", "Moew!"]
|
meows_happy = ['Meow!', 'Nyaa~', 'Mrow.', 'Prr! :3', "Mrrp?", "Mreow.", "!woeM", "3: !rrP", "~aayN", "Mew!", "Moew!"]
|
||||||
meows_upset = ['Hiss!', "!ssiH", "Grrr..."]
|
meows_upset = ['Hiss!', "!ssiH", "Grrr..."]
|
||||||
my_self = ["MeowNexUS", "MeowNexU5", "MeowN3xUS"]
|
my_self = ["MeowNexUS", "MeowNexU5", "MeowN3xUS"]
|
||||||
|
logs = {} # {channel: [line, line]} max 10 lines
|
||||||
happiness = 5
|
happiness = 5
|
||||||
global times
|
global times
|
||||||
times = 0
|
times = 0
|
||||||
|
@ -329,6 +335,10 @@ while True:
|
||||||
print(nick)
|
print(nick)
|
||||||
print(username)
|
print(username)
|
||||||
print(perms)
|
print(perms)
|
||||||
|
cont = " ".join(command)
|
||||||
|
if not channel in logs:
|
||||||
|
logs[channel] = [{nick: nick, content: cont}]
|
||||||
|
if len(logs[channel]) > 10: logs[channel] = logs[channel][:10]
|
||||||
#open("log-text-"+channel, "a").write(" ".join(command) + "\n")
|
#open("log-text-"+channel, "a").write(" ".join(command) + "\n")
|
||||||
#open("log-name-"+channel, "a").write(nick + "\n")
|
#open("log-name-"+channel, "a").write(nick + "\n")
|
||||||
except:
|
except:
|
||||||
|
@ -598,14 +608,47 @@ while True:
|
||||||
|
|
||||||
|
|
||||||
elif command[0] == "$sed":
|
elif command[0] == "$sed":
|
||||||
if len(command) > 1:
|
if len(command) == 1:
|
||||||
|
if channel in logs:
|
||||||
try:
|
try:
|
||||||
#if True:
|
if command[1].split("/")[0].lower() != "s": raise IndexError()
|
||||||
raise Exception("WorkInProgress!!!")
|
find = command[1].split("/")[1]
|
||||||
except:
|
replace = command[1].split("/")[2]
|
||||||
print(traceback.format_exc())
|
user = None
|
||||||
|
repeat = False
|
||||||
|
index = 1
|
||||||
|
try:
|
||||||
|
extraflags = command[1].split("/")[3:]
|
||||||
|
for i in extraflags:
|
||||||
|
if i.lower() == "g":
|
||||||
|
repeat = True
|
||||||
|
elif i.isnumeric():
|
||||||
|
index = int(i)
|
||||||
else:
|
else:
|
||||||
irc.send_irc(channel, nick + ": What to correct?")
|
user = i.lower()
|
||||||
|
cache = None
|
||||||
|
for i in logs[channel]:
|
||||||
|
if find in i["content"] and (user == None or i["nick"] == 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:
|
||||||
|
irc.send_irc(channel, nick + ": [???] This command takes only one argument.")
|
||||||
|
|
||||||
|
|
||||||
elif command[0] == "$config":
|
elif command[0] == "$config":
|
||||||
|
|
Loading…
Reference in a new issue