From af853258c00149509cce871c45eb087d48130aee Mon Sep 17 00:00:00 2001 From: core-hacked Date: Thu, 16 Dec 2021 11:37:50 +0100 Subject: [PATCH] revamp dumb code :ambulance: revamped code that doesn't make sense... --- main.py | 59 ++++++++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/main.py b/main.py index fd0c59f..e7ee490 100644 --- a/main.py +++ b/main.py @@ -3,10 +3,11 @@ import sys import argparse -prefix = str("#DEL") #change this to anything you want so when u type it in the channel it'll delete, or specify it as an argument with --prefix +# Set your defaults below, or specify with the respective arguments +prefix = str("#DEL") token = str("") heartbeat = int(86400) -serverpurge =str("#PS") #change this to anything you want so when u type it in the channel it'll delete, or specify it as an argument with --serverpurge +serverpurge =str("#PS") class MyClient(discord.Client): async def on_message(self, message): @@ -23,18 +24,16 @@ async def on_message(self, message): print(channel) try: async for mss in channel.history(limit=None): - #fetch all message, you might want to purge channel by channel to speedup if the server is old and big + # fetch all message, you might want to purge channel by channel to speed up if the server is old and big if(mss.author==self.user): print(mss.content) try: await mss.delete() except: - print("Can't delete!\n")#this shouldn't happen unless you call purge multiple time + print("Can't delete!\n") # this shouldn't happen unless you call purge multiple time except: print("Can't read history!\n") -#alternatively, remove everything until client=MyClient.. and set your token and prefix at the top. - parser = argparse.ArgumentParser(description='') parser.add_argument('-t','--token', dest='token', type=str, help='Token to use with message purger') parser.add_argument('-p','--prefix', dest='prefix', type=str, help='Prefix to use with message purger') @@ -42,37 +41,18 @@ async def on_message(self, message): parser.add_argument('-b','--heartbeat', dest='heartbeat', type=int, help='Heartbeat timeout to use') args = parser.parse_args() -if args.serverpurge is not None: - serverpurge = args.serverpurge - if args.token is not None: - token = args.token - if args.prefix is not None: - prefix = args.prefix - if args.heartbeat is not None: - heartbeat = args.heartbeat - else: - token = input("Please input a Token: ") - prefix = input("Please input a prefix (leave blank for the default '#DEL'): ") - heartbeat = input("Please input a heartbeat timeout (leave blank for the default 86400): ") - serverpurge = input("Please input a server purge prefix (leave blank for the default '#PS'): ") - if prefix is None: - prefix="#DEL" - if heartbeat is None: - heartbeat = 86400 - if serverpurge is None: - serverpurge = "#PS" +token = args.token +prefix = args.prefix +serverpurge = args.serverpurge +heartbeat = args.heartbeat + +if token is not None: + token = args.token else: - if args.token is not None: - token = args.token - if args.prefix is not None: - prefix = args.prefix - if args.heartbeat is not None: - heartbeat = args.heartbeat - else: - token = input("Please input a Token: ") - prefix = input("Please input a prefix (leave blank for the default '#DEL'): ") - heartbeat = input("Please input a heartbeat timeout (leave blank for the default 86400): ") - serverpurge = input("Please input a server purge prefix (leave blank for the default '#PS'): ") + token = input("Please input a Token: ") + prefix = input("Please input a prefix (leave blank for the default '#DEL'): ") + heartbeat = input("Please input a heartbeat timeout (leave blank for the default 86400): ") + serverpurge = input("Please input a server purge prefix (leave blank for the default '#PS'): ") if prefix is None: prefix="#DEL" if heartbeat is None: @@ -80,6 +60,13 @@ async def on_message(self, message): if serverpurge is None: serverpurge = "#PS" +if prefix is None: + prefix = "#DEL" +if serverpurge is None: + serverpurge = "#PS" +if heartbeat is None: + heartbeat = 86400 + client=MyClient(heartbeat_timeout=heartbeat, guild_subscriptions=False) client.run(token, bot=False)