From b8b0e50ecd654b185d0c14e928bd1c843e8b7b17 Mon Sep 17 00:00:00 2001 From: Marla Date: Mon, 12 Feb 2024 15:06:03 +0100 Subject: [PATCH] added all the files --- bot_newest_version/susmain2_1.py | 308 +++++++++++++++++++++++++ versions/susbot1/commands_scripts1.py | 90 ++++++++ versions/susbot1/funcom_hub1.py | 44 ++++ versions/susbot1/susmain1.py | 173 ++++++++++++++ versions/susmain2.py | 320 ++++++++++++++++++++++++++ versions/susmain2_1.py | 308 +++++++++++++++++++++++++ 6 files changed, 1243 insertions(+) create mode 100644 bot_newest_version/susmain2_1.py create mode 100644 versions/susbot1/commands_scripts1.py create mode 100644 versions/susbot1/funcom_hub1.py create mode 100644 versions/susbot1/susmain1.py create mode 100644 versions/susmain2.py create mode 100644 versions/susmain2_1.py diff --git a/bot_newest_version/susmain2_1.py b/bot_newest_version/susmain2_1.py new file mode 100644 index 0000000..79aa724 --- /dev/null +++ b/bot_newest_version/susmain2_1.py @@ -0,0 +1,308 @@ +import discord, time, random, os, asyncio + + +t_h = 0 +t_s = 0 + + +intents = discord.Intents.default() +intents.message_content = True +intents.members = True +client = discord.Client(intents=intents) + +############################################################################################################## +##################################### COMMNADS AND FUNCTIONS SCRIPTS ######################################### +############################################################################################################## +async def count_reader(message): #returns message with counts of certain word of all users + obsah = message.content.lower().split(' ') + files = [] + user_counts = [] + user_counts_sorted = [] + msg = '' + + if len(obsah) != 2: + print('function ~count got ivalid input:', message.content) + await message.channel.send('invalid input') + return + + else: + slovo = obsah[1] + + if slovo in slova: + directory = os.walk('word_counts') + + for file_path in directory: + for path in file_path[2]: + + if path.startswith(slovo): + files.append(path) + + else: + pass + else: + print('word in not in word list') + await message.channel.send('word is not in word list') + return + + if files == []: + print('word is in the list, but there are no records') + await message.channel.send('word is in the list, but there are no records') + return + + else: + for filey in files: + + split_filey = filey.split(',') + + userid = split_filey[1].split('.') + userid = userid[0] + + path = 'word_counts/' + filey + usercount = open(path, 'r').read() + + user = client.get_user(int(userid)) #needs to be where the client runs (main.py) + + user_counts.append([user.name, usercount]) + + user_counts.sort(key=lambda x:x[1]) + + for g in range(len(user_counts)): + g = len(user_counts) - g - 1 + msg += str(user_counts[g][0]) + ' ---> ' + str(user_counts[g][1]) + '\n' + + await message.channel.send(msg) + +# +# +# +# +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +async def primenum_event(message): #primenumbers script + + vstup = int(message.content.split("~primenum ",1)[1]) + + print('number:', vstup) + + delitel = 1 + vst_up = int(vstup / 2) #vstup děleno dvěmi + nasel = 0 + + if vstup >= 999999: + answer = 'Too big number.' + nasel = 3 + + elif vstup == 2: + answer = str('\nNumber %d IS a prime number.' % (vstup)) + + + else: + vystup = str('Number %d is divisible by:' % (vstup)) + while delitel <= vst_up: + delitel = delitel + 1 + deleno = vstup / delitel + + if deleno == int(deleno): + if delitel == 2: + answer = str('Number %d is divisible by two...' % (vstup)) + nasel = 3 + break + vystup = vystup + "\n " + str(int(deleno)) + nasel = 1 + + if nasel == 0: + answer = str('Number %d IS a prime number.' % (vstup)) + + elif nasel == 1: + answer = vystup + str('\nNumber %d IS NOT a prime number.' % (vstup)) + + await message.channel.send(answer) + print('Bot send:', answer) + + +# +# +# +# +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +async def scprove_event(message): #scientists prove that... script + + input_message = str(message.content.split('~scprove',1)[1]) + + output = str('Scientists prove that') + input_message + ('.') + print('Bot send:', output) + await message.channel.send(output) + +# +# +# +# +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +async def help_event(message): #help script + cc = '' + ff = '' + for C in command_list.values(): + cc = cc + C.help_print() + for C in function_list.values(): + ff = ff + C.help_print() + final_message = '**__Commands__:**\n' + cc + '**__Functions__:**\n' + ff + await message.channel.send(final_message) + +# +# +# +# +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +async def etime_event(message): #epoch time script + await message.channel.send(time.time()) + +############################################################################################################## +##################################### FUNCTIONS AND COMMANDS HUB ############################################# +############################################################################################################## + +class Command: + def __init__(self, caller, desc, script): + self.caller = caller + self.desc = desc + self.script = script + def help_print(self): + return ('%s %s' % (self.caller, self.desc)) + +class Function: + def __init__(self, caller, desc): + self.caller = caller + self.desc = desc + def help_print(self): + return ('%s %s' % (self.caller, self.desc)) + + +function_list = {} + + +function_list['sus'] = Function(' sus', ' --> Bot knows when something is sus\n') + +function_list['hello'] = Function(' greetings', ' --> Bot greets you back\n') + +function_list['counter'] = Function(' word counter', ' --> Bot counts how many times you have written certain words') + +command_list = {} + + +command_list['~etime'] = Command('~etime', ' --> Command that will tell you epoch time\n', etime_event) + +command_list['~help'] = Command('~help', ' --> Command that will show you this list\n', help_event) + +command_list['~primenum'] = Command('~primenum', ' --> Bot will tell you if number is a prime number (number of six digits max.)\n', primenum_event) + +command_list['~scprove'] = Command('~scprove', ' --> Scientist will prove you anything: |*~scprove *|\n', scprove_event) + +command_list['~count'] = Command('~count', ' --> Ask for word count of users: |*~count *|\n\n', count_reader) + + + +slova = ["nigga", "negr", "debil", "gay", "kokot", "ok", "kurva", "sus", "petr", "gej", "bruh", "bružek"] #words bot recognize and count + +sus_responses = ["it's getting sus here", "sus", "you are sussy", "sussy baka", "that is kinda sus", "that is sus"] #variety of responses when sus detection + +greetings =['čau', 'ahoj', 'hi', 'hello', 'high', 'čauky', 'nazdar', 'dobrý den','helou'] #greetings which bot will reply to + +############################################################################################################## +##################################### RUNNING THE FUNCTIONS AND COMMANDS ##################################### +############################################################################################################## + +@client.event #ready message cmd +async def on_ready(): + print("Logged in as {0.user}".format(client)) + + +@client.event #on message actions +async def on_message(message): + global t_h, t_s + if message.author == client.user: + return + + +# +# +# +#accesing functions and commands hub to run commands + if message.content.startswith('~'): + for cmd in command_list.keys(): + if message.content.lower().startswith(cmd): + c = command_list[cmd] + print(message.author.name, '(id:', message.author.id, ')', 'called',c.caller) + await c.script(message) + break + + else: + pass + else: + pass + + +# +# +# +#hello easy function, not in functions_hub + for g in greetings: + if t_h + 30 < time.time(): + if message.content.lower().startswith(g): + await message.channel.send('Hello') + print('Said Hello to:', message.author.name, '(id:', message.author.id,')') + t_h = time.time() + else: + pass + else: + pass + + +# +# +# +#sus easy function, not in functions_hub + if t_s + 20 < time.time(): + if ('sus') in (message.content).lower(): #and message.content[0] != '~': + await message.channel.send(sus_responses[random.randrange(0,len(sus_responses))]) + print('Detected sus from:', message.author.name, '(id:', message.author.id, ')') + t_s = time.time() + else: + pass + else: + pass + + + +# +# +# +#word counter, not in function hub + for slovo in slova: + if slovo in message.content.lower() and message.content[0] != '~': + + + msg_author_id = str(message.author.id) + + count = message.content.lower().count(slovo) + + file_path = str("word_counts/" + slovo + ',' + msg_author_id + ".txt") + + if os.path.exists(file_path): + pass + + else: + file = open(file_path, 'w') + file.write("0") + file.close() + + pocet = open(file_path, 'r').read() + pocet = int(pocet) + count + file = open(file_path, 'w') + file.write(str(pocet)) + file.close() + print("added in", file_path, count, ", celkove", open(file_path, "r").read()) + + else: + pass + + + +client.run("ODk2MzY0NDgxOTYwMTAzOTg2.Gez5r_.q63P7OdNebp2dpHYN7xFUiDLS1TtgpnrTns2O4") diff --git a/versions/susbot1/commands_scripts1.py b/versions/susbot1/commands_scripts1.py new file mode 100644 index 0000000..49c2325 --- /dev/null +++ b/versions/susbot1/commands_scripts1.py @@ -0,0 +1,90 @@ +import funcom_hub1 as fh +import time, random, os, discord + + + + +async def primenum_event(message): #primenumbers script + + + vstup = int(message.content.split("~primenum ",1)[1]) + + print('number:', vstup) + + delitel = 1 + vst_up = int(vstup / 2) #vstup děleno dvěmi + nasel = 0 + + if vstup >= 999999: + answer = 'Too big number.' + nasel = 3 + + elif vstup == 2: + answer = str('\nNumber %d IS a prime number.' % (vstup)) + + + else: + vystup = str('Number %d is divisible by:' % (vstup)) + while delitel <= vst_up: + delitel = delitel + 1 + deleno = vstup / delitel + + if deleno == int(deleno): + if delitel == 2: + answer = str('Number %d is divisible by two...' % (vstup)) + nasel = 3 + break + vystup = vystup + "\n " + str(int(deleno)) + nasel = 1 + + if nasel == 0: + answer = str('Number %d IS a prime number.' % (vstup)) + + elif nasel == 1: + answer = vystup + str('\nNumber %d IS NOT a prime number.' % (vstup)) + + await message.channel.send(answer) + print('Bot send:', answer) + + +# +# +# +# + +async def scprove_event(message): #scientists prove that... script + + input_message = str(message.content.split('~scprove',1)[1]) + + output = str('Scientists prove that') + input_message + ('.') + print('Bot send:', output) + await message.channel.send(output) + +# +# +# +# + +async def help_string(message): #help script + cc = '' + ff = '' + for C in fh.command_list.values(): + cc = cc + C.help_print() + for C in fh.function_list.values(): + ff = ff + C.help_print() + final_message = '**__Commands__:**\n' + cc + '**__Functions__:**\n' + ff + await message.channel.send(final_message) + +# +# +# +# + +async def etime_event(message): #epoch time script + await message.channel.send(time.time()) + +# +# +# + + diff --git a/versions/susbot1/funcom_hub1.py b/versions/susbot1/funcom_hub1.py new file mode 100644 index 0000000..ff1027e --- /dev/null +++ b/versions/susbot1/funcom_hub1.py @@ -0,0 +1,44 @@ +import commands_scripts1 as comcs + +class Command: + def __init__(self, caller, desc, script): + self.caller = caller + self.desc = desc + self.script = script + def help_print(self): + return ('%s %s' % (self.caller, self.desc)) + +class Function: + def __init__(self, caller, desc): + self.caller = caller + self.desc = desc + def help_print(self): + return ('%s %s' % (self.caller, self.desc)) + + +function_list = {} + + +function_list['sus'] = Function(' sus', ' --> Bot knows when something is sus\n') + +function_list['hello'] = Function(' greetings', ' --> Bot greets you back\n') + +function_list['counter'] = Function(' word counter', ' --> Bot counts how many times you have written certain words') + +command_list = {} + + +command_list['~etime'] = Command('~etime', ' --> Command that will tell you epoch time\n', comcs.etime_event) + +command_list['~help'] = Command('~help', ' --> Command that will show you this list\n', comcs.help_string) + +command_list['~primenum'] = Command('~primenum', ' --> Bot will tell you if number is a prime number (number of six digits max.)\n', comcs.primenum_event) + +command_list['~scprove'] = Command('~scprove', ' --> Scientist will prove you anything: |*~scprove *|\n', comcs.scprove_event) + +command_list['~count'] = Command('~count', ' --> Ask for word count of users: |*~count *|\n\n', None) + + + +slova = ["nigga", "negr", "debil", "gay", "kokot", "ok", "kurva", "sus", "petr", "gej", "bruh", "bružek"] + diff --git a/versions/susbot1/susmain1.py b/versions/susbot1/susmain1.py new file mode 100644 index 0000000..cb65e74 --- /dev/null +++ b/versions/susbot1/susmain1.py @@ -0,0 +1,173 @@ +import discord, time, random, os, asyncio +import funcom_hub1 as fh + + +t_h = 0 +t_s = 0 + + +intents = discord.Intents.default() +intents.message_content = True +intents.members = True +client = discord.Client(intents=intents) + +#################################################################### +async def count_reader(message): + obsah = message.content.lower().split(' ') + files = [] + msg = '' + + if len(obsah) != 2: + print('function ~count got ivalid input:', message.content) + await message.channel.send('invalid input') + pass + + else: + slovo = obsah[1] + + if slovo in fh.slova: + directory = os.walk('word_counts') + + + for file_path in directory: + + + for path in file_path[2]: + + + if path.startswith(slovo): + files.append(path) + + else: + pass + if files == []: + print('word is in the list, but there are no records') + await message.channel.send('word is in the list, but there are no records') + + else: + for filey in files: + + split_filey = filey.split(',') + + userid = split_filey[1].split('.') + userid = userid[0] + + path = 'word_counts/' + filey + usercount = open(path, 'r').read() + + user = client.get_user(int(userid)) #needs to be where the client runs (main.py) + + msg += str(user.name) + ' ---> ' + str(usercount) + '\n' + + await message.channel.send(msg) + + else: + print('word in not in word list') + await message.channel.send('word in not in word list') + pass +#################################################################### + + +@client.event #ready message cmd +async def on_ready(): + print("Logged in as {0.user}".format(client)) + + + + +@client.event #on message actions +async def on_message(message): + global t_h, t_s + if message.author == client.user: + return + + +# +# +# +#accesing functions and commands hub to run commands + if message.content.startswith('~'): + print(client.get_user(711564922559004712).name) + for cmd in fh.command_list.keys(): + if message.content.lower().startswith(cmd): + c = fh.command_list[cmd] + print(message.author.name, '(id:', message.author.id, ')', 'called',c.caller) + if c. caller == '~count': + await count_reader(message) + else: + await c.script(message) #krome jednoho prikazu kvuli client.Discord + else: + pass + else: + pass + + + +# +# +# +#sus easy function, not in functions_hub + sus_responses = ["it's getting sus here", "sus", "you are sussy", "sussy baka", "that is kinda sus", "that is sus"] + if t_s + 20 < time.time(): + if ('sus') in (message.content).lower(): + await message.channel.send(sus_responses[random.randrange(0,len(sus_responses))]) + print('Detected sus from:', message.author.name, '(id:', message.author.id, ')') + t_s = time.time() + else: + pass + else: + pass + + + +# +# +# +#hello easy function, not in functions_hub + greetings =['čau', 'ahoj', 'hi', 'hello', 'high', 'čauky', 'nazdar', 'dobrý den','helou'] + for g in greetings: + if t_h + 30 < time.time(): + if message.content.lower().startswith(g): + await message.channel.send('Hello') + print('Said Hello to:', message.author.name, '(id:', message.author.id,')') + t_h = time.time() + else: + pass + else: + pass + + +# +# +# +#word counter, not in function hub + for slovo in fh.slova: + if slovo in message.content.lower() and message.content[0] != '~': + + msg_author_id = str(message.author.id) + + count = message.content.lower().count(slovo) + + file_path = str("word_counts/" + slovo + ',' + msg_author_id + ".txt") + + if os.path.exists(file_path): + pass + + else: + file = open(file_path, 'w') + file.write("0") + file.close() + + pocet = open(file_path, 'r').read() + pocet = int(pocet) + count + file = open(file_path, 'w') + file.write(str(pocet)) + file.close() + print("added in", file_path, count, ", celkove", open(file_path, "r").read()) + + else: + pass + + + +client.run("ODk2MzY0NDgxOTYwMTAzOTg2.Gez5r_.q63P7OdNebp2dpHYN7xFUiDLS1TtgpnrTns2O4") diff --git a/versions/susmain2.py b/versions/susmain2.py new file mode 100644 index 0000000..2d4052f --- /dev/null +++ b/versions/susmain2.py @@ -0,0 +1,320 @@ +import discord, time, random, os, asyncio + + +t_h = 0 +t_s = 0 + + +intents = discord.Intents.default() +intents.message_content = True +intents.members = True +client = discord.Client(intents=intents) + +############################################################################################################## +##################################### COMMNADS AND FUNCTIONS SCRIPTS ######################################### +############################################################################################################## +async def count_reader(message): #returns message with counts of certain word of all users + obsah = message.content.lower().split(' ') + files = [] + user_counts = [] + user_counts_sorted = [] + msg = '' + + if len(obsah) != 2: + print('function ~count got ivalid input:', message.content) + await message.channel.send('invalid input') + return + + else: + slovo = obsah[1] + + if slovo in slova: + directory = os.walk('word_counts') + + for file_path in directory: + for path in file_path[2]: + + if path.startswith(slovo): + files.append(path) + + else: + pass + else: + print('word in not in word list') + await message.channel.send('word is not in word list') + return + + if files == []: + print('word is in the list, but there are no records') + await message.channel.send('word is in the list, but there are no records') + return + + else: + for filey in files: + + split_filey = filey.split(',') + + userid = split_filey[1].split('.') + userid = userid[0] + + path = 'word_counts/' + filey + usercount = open(path, 'r').read() + + user = client.get_user(int(userid)) #needs to be where the client runs (main.py) + + user_counts.append([user.name, usercount]) + + n = len(user_counts) + for i in range(n): + sorted = True + + for j in range(n - i - 1): + if int(user_counts[j][1]) > int(user_counts[j+1][1]): + user_counts[j], user_counts[j+1] = user_counts[j+1], user_counts[j] + sorted = False + + if sorted == True: + break + + for g in range(len(user_counts)): + g = len(user_counts) - g - 1 + msg += str(user_counts[g][0]) + ' ---> ' + str(user_counts[g][1]) + '\n' + + await message.channel.send(msg) + +# +# +# +# +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +async def primenum_event(message): #primenumbers script + + vstup = int(message.content.split("~primenum ",1)[1]) + + print('number:', vstup) + + delitel = 1 + vst_up = int(vstup / 2) #vstup děleno dvěmi + nasel = 0 + + if vstup >= 999999: + answer = 'Too big number.' + nasel = 3 + + elif vstup == 2: + answer = str('\nNumber %d IS a prime number.' % (vstup)) + + + else: + vystup = str('Number %d is divisible by:' % (vstup)) + while delitel <= vst_up: + delitel = delitel + 1 + deleno = vstup / delitel + + if deleno == int(deleno): + if delitel == 2: + answer = str('Number %d is divisible by two...' % (vstup)) + nasel = 3 + break + vystup = vystup + "\n " + str(int(deleno)) + nasel = 1 + + if nasel == 0: + answer = str('Number %d IS a prime number.' % (vstup)) + + elif nasel == 1: + answer = vystup + str('\nNumber %d IS NOT a prime number.' % (vstup)) + + await message.channel.send(answer) + print('Bot send:', answer) + + +# +# +# +# +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +async def scprove_event(message): #scientists prove that... script + + input_message = str(message.content.split('~scprove',1)[1]) + + output = str('Scientists prove that') + input_message + ('.') + print('Bot send:', output) + await message.channel.send(output) + +# +# +# +# +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +async def help_event(message): #help script + cc = '' + ff = '' + for C in command_list.values(): + cc = cc + C.help_print() + for C in function_list.values(): + ff = ff + C.help_print() + final_message = '**__Commands__:**\n' + cc + '**__Functions__:**\n' + ff + await message.channel.send(final_message) + +# +# +# +# +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +async def etime_event(message): #epoch time script + await message.channel.send(time.time()) + +############################################################################################################## +##################################### FUNCTIONS AND COMMANDS HUB ############################################# +############################################################################################################## + +class Command: + def __init__(self, caller, desc, script): + self.caller = caller + self.desc = desc + self.script = script + def help_print(self): + return ('%s %s' % (self.caller, self.desc)) + +class Function: + def __init__(self, caller, desc): + self.caller = caller + self.desc = desc + def help_print(self): + return ('%s %s' % (self.caller, self.desc)) + + +function_list = {} + + +function_list['sus'] = Function(' sus', ' --> Bot knows when something is sus\n') + +function_list['hello'] = Function(' greetings', ' --> Bot greets you back\n') + +function_list['counter'] = Function(' word counter', ' --> Bot counts how many times you have written certain words') + +command_list = {} + + +command_list['~etime'] = Command('~etime', ' --> Command that will tell you epoch time\n', etime_event) + +command_list['~help'] = Command('~help', ' --> Command that will show you this list\n', help_event) + +command_list['~primenum'] = Command('~primenum', ' --> Bot will tell you if number is a prime number (number of six digits max.)\n', primenum_event) + +command_list['~scprove'] = Command('~scprove', ' --> Scientist will prove you anything: |*~scprove *|\n', scprove_event) + +command_list['~count'] = Command('~count', ' --> Ask for word count of users: |*~count *|\n\n', count_reader) + + + +slova = ["nigga", "negr", "debil", "gay", "kokot", "ok", "kurva", "sus", "petr", "gej", "bruh", "bružek"] #words bot recognize and count + +sus_responses = ["it's getting sus here", "sus", "you are sussy", "sussy baka", "that is kinda sus", "that is sus"] #variety of responses when sus detection + +greetings =['čau', 'ahoj', 'hi', 'hello', 'high', 'čauky', 'nazdar', 'dobrý den','helou'] #greetings which bot will reply to + +############################################################################################################## +##################################### RUNNING THE FUNCTIONS AND COMMANDS ##################################### +############################################################################################################## + +@client.event #ready message cmd +async def on_ready(): + print("Logged in as {0.user}".format(client)) + + +@client.event #on message actions +async def on_message(message): + global t_h, t_s + if message.author == client.user: + return + + +# +# +# +#accesing functions and commands hub to run commands + if message.content.startswith('~'): + for cmd in command_list.keys(): + if message.content.lower().startswith(cmd): + c = command_list[cmd] + print(message.author.name, '(id:', message.author.id, ')', 'called',c.caller) + await c.script(message) + break + + else: + pass + else: + pass + + +# +# +# +#hello easy function, not in functions_hub + for g in greetings: + if t_h + 30 < time.time(): + if message.content.lower().startswith(g): + await message.channel.send('Hello') + print('Said Hello to:', message.author.name, '(id:', message.author.id,')') + t_h = time.time() + else: + pass + else: + pass + + +# +# +# +#sus easy function, not in functions_hub + if message.content.startswith('~'): + pass + else: + if t_s + 20 < time.time(): + if ('sus') in (message.content).lower(): + await message.channel.send(sus_responses[random.randrange(0,len(sus_responses))]) + print('Detected sus from:', message.author.name, '(id:', message.author.id, ')') + t_s = time.time() + else: + pass + else: + pass + + + +# +# +# +#word counter, not in function hub + for slovo in slova: + if slovo in message.content.lower() and message.content[0] != '~': + + msg_author_id = str(message.author.id) + + count = message.content.lower().count(slovo) + + file_path = str("word_counts/" + slovo + ',' + msg_author_id + ".txt") + + if os.path.exists(file_path): + pass + + else: + file = open(file_path, 'w') + file.write("0") + file.close() + + pocet = open(file_path, 'r').read() + pocet = int(pocet) + count + file = open(file_path, 'w') + file.write(str(pocet)) + file.close() + print("added in", file_path, count, ", celkove", open(file_path, "r").read()) + + else: + pass + + + +client.run("ODk2MzY0NDgxOTYwMTAzOTg2.Gez5r_.q63P7OdNebp2dpHYN7xFUiDLS1TtgpnrTns2O4") diff --git a/versions/susmain2_1.py b/versions/susmain2_1.py new file mode 100644 index 0000000..79aa724 --- /dev/null +++ b/versions/susmain2_1.py @@ -0,0 +1,308 @@ +import discord, time, random, os, asyncio + + +t_h = 0 +t_s = 0 + + +intents = discord.Intents.default() +intents.message_content = True +intents.members = True +client = discord.Client(intents=intents) + +############################################################################################################## +##################################### COMMNADS AND FUNCTIONS SCRIPTS ######################################### +############################################################################################################## +async def count_reader(message): #returns message with counts of certain word of all users + obsah = message.content.lower().split(' ') + files = [] + user_counts = [] + user_counts_sorted = [] + msg = '' + + if len(obsah) != 2: + print('function ~count got ivalid input:', message.content) + await message.channel.send('invalid input') + return + + else: + slovo = obsah[1] + + if slovo in slova: + directory = os.walk('word_counts') + + for file_path in directory: + for path in file_path[2]: + + if path.startswith(slovo): + files.append(path) + + else: + pass + else: + print('word in not in word list') + await message.channel.send('word is not in word list') + return + + if files == []: + print('word is in the list, but there are no records') + await message.channel.send('word is in the list, but there are no records') + return + + else: + for filey in files: + + split_filey = filey.split(',') + + userid = split_filey[1].split('.') + userid = userid[0] + + path = 'word_counts/' + filey + usercount = open(path, 'r').read() + + user = client.get_user(int(userid)) #needs to be where the client runs (main.py) + + user_counts.append([user.name, usercount]) + + user_counts.sort(key=lambda x:x[1]) + + for g in range(len(user_counts)): + g = len(user_counts) - g - 1 + msg += str(user_counts[g][0]) + ' ---> ' + str(user_counts[g][1]) + '\n' + + await message.channel.send(msg) + +# +# +# +# +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +async def primenum_event(message): #primenumbers script + + vstup = int(message.content.split("~primenum ",1)[1]) + + print('number:', vstup) + + delitel = 1 + vst_up = int(vstup / 2) #vstup děleno dvěmi + nasel = 0 + + if vstup >= 999999: + answer = 'Too big number.' + nasel = 3 + + elif vstup == 2: + answer = str('\nNumber %d IS a prime number.' % (vstup)) + + + else: + vystup = str('Number %d is divisible by:' % (vstup)) + while delitel <= vst_up: + delitel = delitel + 1 + deleno = vstup / delitel + + if deleno == int(deleno): + if delitel == 2: + answer = str('Number %d is divisible by two...' % (vstup)) + nasel = 3 + break + vystup = vystup + "\n " + str(int(deleno)) + nasel = 1 + + if nasel == 0: + answer = str('Number %d IS a prime number.' % (vstup)) + + elif nasel == 1: + answer = vystup + str('\nNumber %d IS NOT a prime number.' % (vstup)) + + await message.channel.send(answer) + print('Bot send:', answer) + + +# +# +# +# +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +async def scprove_event(message): #scientists prove that... script + + input_message = str(message.content.split('~scprove',1)[1]) + + output = str('Scientists prove that') + input_message + ('.') + print('Bot send:', output) + await message.channel.send(output) + +# +# +# +# +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +async def help_event(message): #help script + cc = '' + ff = '' + for C in command_list.values(): + cc = cc + C.help_print() + for C in function_list.values(): + ff = ff + C.help_print() + final_message = '**__Commands__:**\n' + cc + '**__Functions__:**\n' + ff + await message.channel.send(final_message) + +# +# +# +# +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +async def etime_event(message): #epoch time script + await message.channel.send(time.time()) + +############################################################################################################## +##################################### FUNCTIONS AND COMMANDS HUB ############################################# +############################################################################################################## + +class Command: + def __init__(self, caller, desc, script): + self.caller = caller + self.desc = desc + self.script = script + def help_print(self): + return ('%s %s' % (self.caller, self.desc)) + +class Function: + def __init__(self, caller, desc): + self.caller = caller + self.desc = desc + def help_print(self): + return ('%s %s' % (self.caller, self.desc)) + + +function_list = {} + + +function_list['sus'] = Function(' sus', ' --> Bot knows when something is sus\n') + +function_list['hello'] = Function(' greetings', ' --> Bot greets you back\n') + +function_list['counter'] = Function(' word counter', ' --> Bot counts how many times you have written certain words') + +command_list = {} + + +command_list['~etime'] = Command('~etime', ' --> Command that will tell you epoch time\n', etime_event) + +command_list['~help'] = Command('~help', ' --> Command that will show you this list\n', help_event) + +command_list['~primenum'] = Command('~primenum', ' --> Bot will tell you if number is a prime number (number of six digits max.)\n', primenum_event) + +command_list['~scprove'] = Command('~scprove', ' --> Scientist will prove you anything: |*~scprove *|\n', scprove_event) + +command_list['~count'] = Command('~count', ' --> Ask for word count of users: |*~count *|\n\n', count_reader) + + + +slova = ["nigga", "negr", "debil", "gay", "kokot", "ok", "kurva", "sus", "petr", "gej", "bruh", "bružek"] #words bot recognize and count + +sus_responses = ["it's getting sus here", "sus", "you are sussy", "sussy baka", "that is kinda sus", "that is sus"] #variety of responses when sus detection + +greetings =['čau', 'ahoj', 'hi', 'hello', 'high', 'čauky', 'nazdar', 'dobrý den','helou'] #greetings which bot will reply to + +############################################################################################################## +##################################### RUNNING THE FUNCTIONS AND COMMANDS ##################################### +############################################################################################################## + +@client.event #ready message cmd +async def on_ready(): + print("Logged in as {0.user}".format(client)) + + +@client.event #on message actions +async def on_message(message): + global t_h, t_s + if message.author == client.user: + return + + +# +# +# +#accesing functions and commands hub to run commands + if message.content.startswith('~'): + for cmd in command_list.keys(): + if message.content.lower().startswith(cmd): + c = command_list[cmd] + print(message.author.name, '(id:', message.author.id, ')', 'called',c.caller) + await c.script(message) + break + + else: + pass + else: + pass + + +# +# +# +#hello easy function, not in functions_hub + for g in greetings: + if t_h + 30 < time.time(): + if message.content.lower().startswith(g): + await message.channel.send('Hello') + print('Said Hello to:', message.author.name, '(id:', message.author.id,')') + t_h = time.time() + else: + pass + else: + pass + + +# +# +# +#sus easy function, not in functions_hub + if t_s + 20 < time.time(): + if ('sus') in (message.content).lower(): #and message.content[0] != '~': + await message.channel.send(sus_responses[random.randrange(0,len(sus_responses))]) + print('Detected sus from:', message.author.name, '(id:', message.author.id, ')') + t_s = time.time() + else: + pass + else: + pass + + + +# +# +# +#word counter, not in function hub + for slovo in slova: + if slovo in message.content.lower() and message.content[0] != '~': + + + msg_author_id = str(message.author.id) + + count = message.content.lower().count(slovo) + + file_path = str("word_counts/" + slovo + ',' + msg_author_id + ".txt") + + if os.path.exists(file_path): + pass + + else: + file = open(file_path, 'w') + file.write("0") + file.close() + + pocet = open(file_path, 'r').read() + pocet = int(pocet) + count + file = open(file_path, 'w') + file.write(str(pocet)) + file.close() + print("added in", file_path, count, ", celkove", open(file_path, "r").read()) + + else: + pass + + + +client.run("ODk2MzY0NDgxOTYwMTAzOTg2.Gez5r_.q63P7OdNebp2dpHYN7xFUiDLS1TtgpnrTns2O4")