discord_susbot/versions/susbot1/susmain1.py
2024-02-12 15:06:03 +01:00

174 lines
4.4 KiB
Python

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")