started making susbot3

This commit is contained in:
Honza
2024-03-15 14:50:42 +01:00
parent 80aad63031
commit ad57fcadf5
2 changed files with 322 additions and 4 deletions
@@ -1,4 +1,5 @@
import discord, time, random, os, asyncio
import discord, time, random, os
from discord.ext import commands
t_h = 0
@@ -6,18 +7,50 @@ t_s = 0
intents = discord.Intents.default()
intents.message_content = True
intents.messages = True
intents.members = True
client = discord.Client(intents=intents)
client = commands.Bot(command_prefix = '~', intents=intents)
##############################################################################################################
##################################### COMMNADS AND FUNCTIONS SCRIPTS #########################################
##############################################################################################################
async def count_reader(message): #returns message with counts of certain word of all users
async def word_counter(message): #counts words in word list
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
#
#
#
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
async def count_reader(message): #count command 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:
@@ -155,6 +188,39 @@ async def help_event(message): #help script
async def etime_event(message): #epoch time script
await message.channel.send(time.time())
#
#
#
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
async def greetings_function(message): #greetings function
if t_h + 30 < time.time():
for g in greetings:
if message.content.lower().startswith(g):
await message.channel.send('Hello')
print('Expressed greetings to:', message.author.name, '(id:', message.author.id,')')
t_h = time.time()
else:
pass
else:
pass
#
#
#
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
async def sus_function(message): #sus function
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
##############################################################################################################
##################################### FUNCTIONS AND COMMANDS HUB #############################################
##############################################################################################################
@@ -219,89 +285,34 @@ async def on_message(message):
global t_h, t_s
if message.author == client.user:
return
# else:
# await(greetings_function(message))
# await(sus_function(message))
# await(word_counter(message))
@client.command()
async def count(ctx, *, arg):
await(count_reader(arg))
#
#
#
#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
# 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
#
#
#
#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('Expressed greetings 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
# else:
# pass
# else:
# pass
TOKEN = open("../sus_bot_token.txt", 'r').read()
client.run(TOKEN)