Skip to content
This repository was archived by the owner on Mar 25, 2023. It is now read-only.

Commit bb9f55e

Browse files
committed
Cleanup and fixup 2
Round 2 cleaned up the modules this time just misc stuff really
1 parent cdf2c73 commit bb9f55e

File tree

5 files changed

+30
-35
lines changed

5 files changed

+30
-35
lines changed

modules/Deathbattle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def __init__(self,hitMsg,dmgMin,dmgMax):
88
def __str__(self):
99
return self.hitMsg
1010
def format(self,attacker,victim,damage):
11-
return self.hitMsg.format(attacker="__**"+str(attacker)+"**__",victim="__**"+str(victim)+"**__",damage="__**"+str(damage)+" dmg**__")
11+
return self.hitMsg.format(attacker=f"__**{attacker}**__",victim=f"__**{victim}**__",damage=f"__**{damage} dmg**__")
1212
def hit(self):
1313
return random.randint(self.dmgMin,self.dmgMax)
1414
class user:

modules/Dev.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async def d_execa(msg,args):
1818
try:
1919
await globals()[args[2]]()
2020
except Exception as exc:
21-
print("[Dev] Nice custom async exec, but it failed. Command:",msg.content[10:],"Exception:",exc)
21+
print("[Dev] Nice custom async exec, but it failed. Command:",args[2],"Exception:",exc)
2222
await msg.channel.send(":-1: "+str(exc))
2323
else:
2424
print("[Dev] Successful async exec")
@@ -32,6 +32,12 @@ async def sendLogFile(msg,args):
3232
await msg.channel.send("No such log file "+str(exists(args,1) and args[1]))
3333
Command("sendlog",sendLogFile,0,"Sends the log file specified if it exists",{"log":True},None,"dev")
3434

35+
async def getPing(msg,args):
36+
startTime = time.time()
37+
message = await msg.channel.send("<???> ms")
38+
await message.edit(content=str(round((time.time()-startTime)*1000))+" ms")
39+
Command("ping",getPing,0,"Uses the time it takes to send a message to calculate its ping",{},None,"dev")
40+
3541
async def currentDateAsync(msg,args):
3642
await msg.channel.send(currentDate())
3743
Command("cdate",currentDateAsync,0,"Sends the current date and time as a message",{},None,"dev")
@@ -46,7 +52,7 @@ async def presetAudioTest(msg,args):
4652
return
4753
if not exists(args,1):
4854
args.insert(1,"sigma")
49-
file = "storage/temp/"+args[1]+".mp3"
55+
file = f"storage/temp/{args[1]}.mp3"
5056
vc = await connectToVC(msg.author.voice.channel,idleTimeout=1,ignorePlaying=True) #Join
5157
if not vc:
5258
await msg.channel.send("Couldnt join the vc, probably cause i was busy")
@@ -86,9 +92,3 @@ async def imageComp(msg,args): #Just a POC, not used meaningfully
8692
await msg.channel.send(targetUser.name+" in a box",file=discord.File(fileName))
8793
os.remove(fileName)
8894
Command("imaget",imageComp,0,"An experiment with image editing",{"user":False},None,"dev")
89-
90-
async def getPing(msg,args):
91-
startTime = time.time()
92-
message = await msg.channel.send("<???> ms")
93-
await message.edit(content=str(round((time.time()-startTime)*1000))+" ms")
94-
Command("ping",getPing,0,"Uses the time it takes to send a message to calculate its ping",{},None,"dev")

modules/Moderation.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ async def list_func(msg,args):
3636
return
3737
parser = None
3838
if section in ["WordBlockList","MediaFilters","ChannelClearList","QueuedChannels"]:
39-
parser = lambda i,k,v : f"{str(i)}. `{k}` -> {simplifySeconds(v)}"
39+
parser = lambda i,k,v : f"{i}. `{k}` -> {simplifySeconds(v)}"
4040
if section in ["NSFWBlockList","ProtectedMessages"]:
41-
parser = lambda i,v : f"{str(i)}. `{v}`"
41+
parser = lambda i,v : f"{i}. `{v}`"
4242
if section == "ChannelLimits":
43-
parser = lambda i,k,v : f"{str(i)}. `{k}` -> {str(v)} Messages"
43+
parser = lambda i,k,v : f"{i}. `{k}` -> {v} Messages"
4444
array = getattr(getMegaTable(msg),section)
4545
finalString = []
4646
index = 1
@@ -55,7 +55,7 @@ async def list_func(msg,args):
5555
if finalString == []:
5656
await msg.channel.send(embed=fromdict({"title":"No Content","description":"Nothing under this catagory","color":colours["warning"]}),delete_after=15)
5757
else:
58-
getMegaTable(msg).ProtectedMessages.append((await createPagedEmbed(msg.author,msg.channel,"List of moderation content",finalString,8,(section=="QueuedChannels" and "(This is how long until the next cycle)") or "")).id)
58+
getMegaTable(msg).ProtectedMessages.append((await createPagedEmbed(msg.author,msg.channel,"List of moderation content",finalString,8,(section=="QueuedChannels" and "(How long until the next cycle)") or "")).id)
5959
Command("list",list_func,0,"View the list of settings to do with the server's administration",{"subsection":False},None,"admin")
6060

6161
async def refilter(msg,args):
@@ -84,7 +84,7 @@ async def protectMessage(msg,args): #Prevents a message from being filtered
8484
await msg.channel.send(embed=fromdict({"title":"Error","description":"You must provide the message ID to protect","color":colours["error"]}),delete_after=10)
8585
return
8686
try:
87-
msgid = int(msgid)//1
87+
msgid = int(msgid)
8888
except:
8989
await msg.channel.send(embed=fromdict({"title":"Error","description":"message ID must be a number","color":colours["error"]}),delete_after=10)
9090
else:
@@ -196,7 +196,7 @@ async def controlMessageLimit(msg,args,removing):
196196
if msgLimit <= 0:
197197
await channel.send(embed=fromdict({"title":"No","description":"1 or more, no less","color":colours["error"]}),delete_after=10)
198198
gmt.ChannelLimits[str(channel.id)] = msgLimit #JSON Logic
199-
await channel.send(embed=fromdict({"title":"Success","description":f"All messages after #{str(msgLimit)} will be auto-deleted","color":colours["success"]}))
199+
await channel.send(embed=fromdict({"title":"Success","description":f"All messages after #{msgLimit} will be auto-deleted","color":colours["success"]}))
200200
else:
201201
if exists(gmt.ChannelLimits,channel.id):
202202
gmt.ChannelLimits.pop(channel.id)
@@ -224,15 +224,15 @@ async def clearAllInvites(msg,args,silent=False):
224224
if silent:
225225
return True,f"{str(successRate)}/{str(totalCount)}"
226226
else:
227-
await msg.channel.send(embed=fromdict({"title":"Success","description":f"{str(successRate)} out of {str(totalCount)} invites were successfully cleared","color":colours["success"]}))
227+
await msg.channel.send(embed=fromdict({"title":"Success","description":f"{successRate} out of {totalCount} invites were successfully cleared","color":colours["success"]}))
228228
async def clearInvitesConfirm(msg,args):
229229
await getMegaTable(msg).CreateConfirmation(msg,args,clearAllInvites)
230230
Command("clearinvites",clearInvitesConfirm,5,"Clears all invites in the server, deleting them",{},None,"admin")
231231

232-
async def panic(msg,args):
232+
async def panic(msg,args): #Unfinished!
233233
finalString = ""
234234
success,result = await clearAllInvites(msg,args,True)
235-
finalString += "Invite clear: "+(success and "Sucessfully cleared "+result+" invites\n") or "Failed\n"
235+
finalString += "Invite clear: "+(success and f"Sucessfully cleared {result} invites\n") or "Failed\n"
236236
await msg.channel.send(embed=fromdict({"title":"Panic results:","description":finalString,"color":colours["info"]}))
237237
async def confirmPanic(msg,args):
238238
await getMegaTable(msg).CreateConfirmation(msg,args,panic)

modules/NSFW.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,17 @@ async def getPostList(msg,sitetype,tags):
9191
anyMessageFiltered = True
9292
if len(returnContent) == 0:
9393
if anyMessageFiltered:
94-
await msg.channel.send(embed=fromdict({"title":"Post Blocked","description":"The recieved post contained one or more blocked tags","color":colours["error"]})) #No
94+
await msg.channel.send(embed=fromdict({"title":"Post Blocked","description":"The recieved post contained one or more blocked tags","color":colours["error"]}),delete_after=15) #No
9595
else:
96-
await msg.channel.send(embed=fromdict({"title":"No Posts","description":"No posts were found under your requested tags","color":colours["error"]})) #Consider adding delete_after
96+
await msg.channel.send(embed=fromdict({"title":"No Posts","description":"No posts were found under your requested tags","color":colours["error"]}),delete_after=15)
9797
return
9898
return returnContent
9999
async def nsfwScrape(msg,args,sitetype): #I spent hours on this and idk if i should be happy about it
100100
if not msg.channel.is_nsfw():
101101
await msg.channel.send(embed=fromdict({"title":"Disallowed","description":"You can only use NSFW commands in channels marked as NSFW","color":colours["error"]}),delete_after=10)
102102
return
103-
tags = ""
104-
for i in args[1:]: #Avoid calling command
105-
tags = tags+i+"+" #A trailing + is fine
106103
try:
107-
postList = await getPostList(msg,sitetype,tags) #HTTP Requests, therefore try: it
104+
postList = await getPostList(msg,sitetype,"+".join(args[1:])) #HTTP Requests, therefore try: it
108105
except Exception as exc:
109106
log(f"[NSFW] {sitetype} GetPosts Exception: "+str(exc))
110107
await msg.channel.send(embed=fromdict({"title":"Unexpected Error","description":"Something unexpected went wrong, hopefully it wont happen again","color":colours["error"]}),delete_after=10)

modules/Tests.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#Seperate script to improve ##cmds ordering and for convenience
22
TestCommandList = []
33
def AddCommand(a,b,c,d,e,f):
4-
cmdObject = Command(a,b,c,d,e,f,"dev")
5-
if a != "d -test onerror":
6-
TestCommandList.append(cmdObject)
4+
TestCommandList.append(Command(a,b,c,d,e,f,"dev"))
75

8-
async def horribleCoding(msg,args):
9-
[] # This is just designed to error
10-
AddCommand("d -test error",horribleCoding,0,"Forces an error to test the error logging",{},None)
6+
async def forceOnError(msg,args):
7+
await on_error(msg)
8+
AddCommand("d -test onerror",forceOnError,0,"Forces an error to test the error logging",{},None)
119
async def forceOnReady(msg,args):
1210
await on_ready()
1311
AddCommand("d -test onready",forceOnReady,0,"Runs the on_ready function",{},None)
@@ -19,12 +17,12 @@ async def testConfirmations(msg,args):
1917
AddCommand("d -test confirmations",testConfirmations,0,"Tests the Confirmations feature",{},None)
2018
async def testReactionListener2(msg,emoji,score):
2119
score += 1
22-
await msg.edit(content=f"This message + {str(score)}")
20+
await msg.edit(content=f"This message + {score}")
2321
await UpdateReactionWatch(msg,"all",score)
2422
async def testReactionListener(msg,args):
2523
message = await msg.channel.send("This message + 0")
2624
await message.add_reaction("⬅️")
27-
WatchReaction(message,msg.author,"⬅",testReactionListener2,0)
25+
WatchReaction(message,msg.author,"⬅",testReactionListener2,0)
2826
AddCommand("d -test reactions",testReactionListener,0,"Tests the Reaction Listener",{},None)
2927
async def testPagedEmbed(msg,args): #user, channel, title, content, pagelimit
3028
await createPagedEmbed(msg.author,msg.channel,msg.author.name,["A","B","C","D","E","F","G","H","I","J"],4)
@@ -41,9 +39,9 @@ async def testAll(msg,args):
4139
else:
4240
print("Failed run of",command.Name)
4341
except Exception as exc:
44-
print("Critical fail run of",command.Name,":",exc)
42+
print(f"Critical fail run of {command.Name}: {exc}")
4543
score[0] += 1
46-
await msg.channel.send(f"All tests finished: Final score {str(score[1])} out of {str(score[0])}")
44+
await msg.channel.send(f"All tests finished: Final score {score[1]} out of {score[0]}")
4745
print("Test-All final score",score)
4846
Command("d -test all",testAll,0,"Runs all 'd -test' commands and returns the success score",{},None,"dev")
4947
AddCommand = None
@@ -86,7 +84,7 @@ def __init__(self,content=None,embed=None,gid=None,uid=None):
8684
async def delete(self):
8785
print("Tried to delete message",self.id,self.content)
8886

89-
async def AdvancedTest(msg,args):
87+
async def AdvancedTest(msg,args): #Possibly OTT
9088
print("Trying advanced test")
9189
fm = FakeMessage
9290
await on_message(fm("##blockword testing 1s",gid=-1)) #Should work - user is admin

0 commit comments

Comments
 (0)