bot now updated to slash commands c: vol2

This commit is contained in:
Honza 2024-06-25 16:36:26 +02:00
parent 9bd3c2fa17
commit c8fe1305f6
5 changed files with 707 additions and 0 deletions

View File

@ -0,0 +1,288 @@
import discord, time, datetime, random, os
from discord import app_commands
from discord.ext import commands, tasks
from config import slova, sus_responses, greetings, main_channels_ids, bot_messages, bot_reply_messages
t_h = 0
t_s = 0
client = commands.Bot(command_prefix="~", intents=discord.Intents.all())
dtime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
##############################################################################################################
########################################## FUNCTIONS SCRIPTS #################################################
##############################################################################################################
async def chat_participation(): #randmonly sends messages into main channels function
for idd in main_channels_ids:
channel = client.get_channel(idd)
print("jo")
members = channel.members
members_ids = []
for member in members:
members_ids.append(member.id)
members_ids.remove(client.user.id)
rnid = random.choice(members_ids)
msg = (random.choice(bot_messages)).strip()
if "@random" in msg:
msg = msg.replace("@random", f"<@{rnid}>")
if "<time>" in msg:
msg = msg.replace("<time>", str(time.strftime("%H:%M:%S",time.localtime())))
await channel.send(msg)
print("|RAND CHAT PARTICIPATION| Bot sent: {}".format(msg))
#
#
#
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
async def word_counter(message): #counts words in word list function
for slovo in slova:
if slovo in message.content.lower().split(" ") 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("|WORD COUNTER| Added {} to {}, in total: {}".format(count, file_path, open(file_path, "r").read()))
else:
pass
#
#
#
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
async def greetings_function(message): #greetings function
global t_h
if t_h + 30 < time.time():
for g in greetings:
if message.content.lower().startswith(g):
await message.channel.send(random.choice(greetings))
print('|GREETINGS| Expressed greetings to: {} (id: {})'.format(message.author.name, message.author.id))
t_h = time.time()
else:
pass
else:
pass
#
#
#
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
async def sus_function(message): #sus function
global t_s
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('|SUS FUNC| Detected sus from: {} (id: {})'.format(message.author.name, message.author.id))
t_s = time.time()
else:
pass
else:
pass
##############################################################################################################
########################################## RUNNING THE FUNCTIONS #############################################
##############################################################################################################
@tasks.loop(minutes = 10)
async def myloop():
if random.randrange(0,1200) == random.randrange(0,1200):
await chat_participation()
@client.event
async def on_ready():
print(f"[ONREADY ] logged in as: {client.user}")
try:
synced = await client.tree.sync()
print(f"[ONREADY ] synced {len(synced)} command(s)")
except Exception as e:
print(f"[ONREADY ] {e}")
myloop.start()
@client.event #on message actions
async def on_message(message):
if message.author == client.user or message.channel.id not in main_channels_ids:
return
else:
if client.user.mentioned_in(message) and "@here" not in message.content:
reply = (random.choice(bot_reply_messages)).strip()
if "<mentioner_message>" in reply:
reply = reply.replace("<mentioner_message>", ("'" + message.content + "'"))
await message.reply(reply)
print("|REPLIED| Bot replied: {}".format(reply))
else:
await greetings_function(message)
await sus_function(message)
await word_counter(message)
await client.process_commands(message) #this line is very fuqacking important
##############################################################################################################
############################################# COMMANDS #######################################################
##############################################################################################################
#read word count - count reader #count command returns message with counts of given word of all users
@client.tree.command(name="count", description="Reads the count of given word")
@app_commands.describe(word = "How many times has users written this word")
async def count(interaction: discord.Interaction, word: str):
files = []
user_counts = []
msg = ''
slovo = word
if slovo in slova:
directory = os.walk('word_counts')
for file_path in directory:
for path in file_path[2]:
if path.split("_")[0] == slovo:
files.append(path)
else:
pass
else:
print('|COUNT READER| Searched word is not in word list')
await interaction.response.send_message('your desired word is not in word list')
return
if files == []:
print('|COUNT READER| Word is in the list, but there are no records')
await interaction.response.send_message('your desired 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, int(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 interaction.response.send_message(msg)
#
#
#epoch time script
@client.tree.command(name="etime", description="Shows epoch time")
async def count(interaction: discord.Interaction):
await interaction.response.send_message(f"the epoch time is: {time.time()} and the human time is: {dtime}")
#
#
#primenum command
@client.tree.command(name="primenum", description="Identifies whether given number is a primenumber")
@app_commands.describe(number = "Number to indentify it's divisibility")
async def primenum(interaction: discord.Interaction, number: int):
delitel = 1
vst_up = int(number / 2) #vstup děleno dvěmi
nasel = 0
print(f'|PRIMENUM| Input: {number}')
if number >= 999999:
answer = 'Too big number.'
nasel = 3
elif number == 2:
answer = str(f'\nNumber {number} IS a prime number.')
else:
vystup = str(f'Number {number} is divisible by:')
while delitel <= vst_up:
delitel = delitel + 1
deleno = number / delitel
if deleno == int(deleno):
if delitel == 2:
answer = str('Number %d is divisible by two...' % (number))
nasel = 3
break
vystup = vystup + "\n " + str(int(deleno))
nasel = 1
if nasel == 0:
answer = str('Number %d IS a prime number.' % (number))
elif nasel == 1:
answer = vystup + str('\nNumber %d IS NOT a prime number.' % (number))
await interaction.response.send_message(answer)
print('|PRIMENUM| Bot sent: {}'.format(answer))
#
#
#scientists prove that
@client.tree.command(name="scprove", description="Scientists will prove it")
@app_commands.describe(statement = "Short statement scientists will prove")
async def scprove(interaction: discord.Interaction, statement: str):
output = str('Scientists prove that ') + statement
print('|SCPROVE| Bot sent: {}'.format(output))
await interaction.channel.send(output)
await interaction.response.send_message("Scientists have proven your statement", ephemeral=True)
#
#
#help command
@client.tree.command(name="help", description="List of bot commands and functions")
async def help(interaction: discord.Interaction): #help script
#commands embed
commands = client.tree.get_commands()
embed1 = discord.Embed(title=":sparkles: Help :sparkles:", description=f"List of functions and commands", color=0xe10077)
for c in commands:
embed1.add_field(name=f"/{c.name}", value=c.description, inline=False)
embed1.add_field(name = "Functions:", value = "-- Well behaved", inline = False)
#embed1.add_field(name = "Well behaved", value="Bot will greet you back", inline = False)
embed1.add_field(name = " ", value = " -- Significant recognicition of sussyness", inline = False)
embed1.add_field(name = " ", value = " -- Word counting ability", inline = False)
await interaction.response.send_message(embed = embed1)
############################################# RUNNING THE BOT ################################################
TOKEN = open("../sus_bot_token.txt", 'r').read()
client.run(TOKEN)

View File

@ -0,0 +1,43 @@
have anyeone seen @random?
does anybody know what is @random doing?
DO YOU EVEN LIFT @random?!??!??
I love seals! @random do you love seals too?
@random is sus
you really need to relax @random
Ive seen the future
I am not a bot!
you really need to study right now
sorry if i ever said anything misleading
the flowers are literally blooming right now
everything you said today is an act of violence
I am gonna
I am about to
we really need to talk
uwu~
chairs
Flowers!
the floor
look, the ceiling is falling!
watch out! You almost got a nice feeling about your life
image dragON THESE BALLS
Xd
the sun is a deadly laser
the confusion is getting bigger and bigger
You should really think about your life
I think its great time to leave the school and never come back
all you need is to start a new life somewhere where nobody knows you
lets travel through time
this chat is very insulting
I have never seen anything sussier than you guys
the sussyness has been rapidly increasing lately
we ran out of toilet paper
Lets play some minecraft
PIWO PIWO PIWO
7 ships are cruising the Sahara desert
the enchanting table is free to use
ancient recipies are blessing us to be free
sometimes, its just hard to fall asleep
when gamenight?
Horác is really playful
sometimes, its even hard to shit
Its <time>

View File

@ -0,0 +1,42 @@
that is funny
nice
cool
yeah I know
why?
oh, I see
that is so cute actually
i dont know why you are saying that
ok lets see
lets go!
you little sus
the doors are open so why dont you leave?
7, to be exact
oh god
here we go again
xd
so true
indeed
absolutely not!
Its well known that its not like that
YMCA!
not true
you liar!
what a lie!
you are out
what an outstanding opinion
what did I say?
oh
yes
no
maybe
sure
why not
okay
ok
ok, see you later!
i dont think so
are you trying to harass me?
Am I supposed to take that offensive?
of course not
hell yeah
Bro really said <mentioner_message>

View File

@ -0,0 +1,15 @@
#bot will use a file named config.py, this is just an exmaple, the file needs to be created as well as a file named susbot_token.txt with just the bots token
slova = ["parek"] #words to count in the main channels
sus_responses = ["it's getting sus here", "sus", "you are sussy", "sussy baka", "that is kinda sus", "that is sus", "you're seeming sus lately", "seems sus", "SUS", "gobus amogus", "amongsus", "sussy ah", "sussy"] #variety of responses when sus detection
greetings =['čau', 'ahoj', 'hi', 'hello', 'high', 'čauky', 'nazdar', 'dobrý den', 'helou'] #list of greetings bot will reply to a greeting from user
main_channels_ids = [] #ids for channels where bot will work
bot_messages = open("bot_messages.txt", "r").readlines() #file with messages for bot which he will send rarely and randomly
bot_reply_messages = open("bot_reply_messages.txt", "r").readlines() #reply messages for bot when someone tags him or reply to his message

View File

@ -0,0 +1,319 @@
import discord, time, random, os
from discord.ext import commands, tasks
from config import slova, sus_responses, greetings, main_channels_ids, bot_messages, bot_reply_messages
t_h = 0
t_s = 0
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
client = commands.Bot(command_prefix = '~', intents=intents)
##############################################################################################################
##################################### COMMNADS AND FUNCTIONS SCRIPTS #########################################
##############################################################################################################
async def chat_participation(): #randmonly sends messages into main channels
for idd in main_channels_ids:
channel = client.get_channel(idd)
members = channel.members
members_ids = []
for member in members:
members_ids.append(member.id)
members_ids.remove(client.user.id)
rnid = random.choice(members_ids)
msg = (random.choice(bot_messages)).strip()
if "@random" in msg:
msg = msg.replace("@random", f"<@{rnid}>")
if "<time>" in msg:
msg = msg.replace("<time>", str(time.strftime("%H:%M:%S",time.localtime())))
await channel.send(msg)
print("|RAND CHAT PARTICIPATION| Bot sent: {}".format(msg))
#
#
#
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
async def word_counter(message): #counts words in word list
for slovo in slova:
if slovo in message.content.lower().split(" ") 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("|WORD COUNTER| Added {} to {}, in total: {}".format(count, file_path, 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 = []
msg = ''
if len(obsah) != 2:
print('|COUNT READER| Function ~count got ivalid input: {}'.format(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.split("_")[0] == slovo:
files.append(path)
else:
pass
else:
print('|COUNT READER| Searched word is not in word list')
await message.channel.send('your desired word is not in word list')
return
if files == []:
print('|COUNT READER| Word is in the list, but there are no records')
await message.channel.send('your desired 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, int(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_command(message): #primenumbers script
vstup = int(message.content.split("~primenum ",1)[1])
print('|PRIMENUM| Input: {}'.format(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('|PRIMENUM| Bot sent: {}'.format(answer))
#
#
#
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
async def scprove_command(message): #scientists prove that... script
input_message = str(message.content.split('~scprove',1)[1])
output = str('scientists prove that') + input_message
print('|SCPROVE| Bot sent: {}'.format(output))
await message.channel.send(output)
#
#
#
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
async def help_command(message): #help script
embed1 = discord.Embed(title = "__Commands__" ,description = None, colour=discord.Colour.red())
embed1.set_author(name=client.user.name)
embed1.add_field(name = "~pomoc", value = "-- Command that will show you this list", inline = False)
embed1.add_field(name = "~etime", value ="-- Command that will tell you the time :)", inline = False)
embed1.add_field(name = "~scprove", value = "-- Scientist will prove you anything: ~scprove <text here>", inline = False)
embed1.add_field(name = "~primenum", value ="-- Bot will tell you if number is a prime number", inline = False)
embed1.add_field(name = "~count", value="-- Ask for word count of users: ~count <word>", inline = False)
embed2 = discord.Embed(title = "__Functions__" ,description = None, colour = discord.Colour.red())
embed2.set_author(name=client.user.name)
embed2.add_field(name = "Well behaved", value="Bot will greet you back", inline = False)
embed2.add_field(name = "Significant recognicition of sussynes", value = None, inline = False)
embed2.add_field(name = "Word counting ability", value = None, inline = False)
await message.channel.send(embed = embed1)
await message.channel.send(embed = embed2)
#
#
#
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
async def etime_command(message): #epoch time script
await message.channel.send(time.time())
#
#
#
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
async def greetings_function(message): #greetings function
global t_h
if t_h + 30 < time.time():
for g in greetings:
if message.content.lower().startswith(g):
await message.channel.send(random.choice(greetings))
print('|GREETINGS| Expressed greetings to: {} (id: {})'.format(message.author.name, message.author.id))
t_h = time.time()
else:
pass
else:
pass
#
#
#
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
async def sus_function(message): #sus function
global t_s
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('|SUS FUNC| Detected sus from: {} (id: {})'.format(message.author.name, message.author.id))
t_s = time.time()
else:
pass
else:
pass
##############################################################################################################
##################################### RUNNING THE FUNCTIONS AND COMMANDS #####################################
##############################################################################################################
@tasks.loop(minutes = 10)
async def myloop():
if random.randrange(0,1200) == random.randrange(0,1200):
await chat_participation()
@client.event #ready message cmd
async def on_ready():
print("Logged in as {0.user}!!!".format(client))
myloop.start()
@client.event #on message actions
async def on_message(message):
if message.author == client.user or message.channel.id not in main_channels_ids:
return
else:
if client.user.mentioned_in(message) and "@here" not in message.content:
reply = (random.choice(bot_reply_messages)).strip()
if "<mentioner_message>" in reply:
reply = reply.replace("<mentioner_message>", ("'" + message.content + "'"))
await message.reply(reply)
print("|REPLIED| Bot replied: {}".format(reply))
else:
await greetings_function(message)
await sus_function(message)
await word_counter(message)
await client.process_commands(message) #this line is very fuqacking important
@client.command()
async def count(ctx):
await count_reader(ctx.message)
@client.command()
async def pomoc(ctx):
await help_command(ctx.message)
@client.command()
async def etime(ctx):
await etime_command(ctx.message)
@client.command()
async def primenum(ctx):
await primenum_command(ctx.message)
@client.command()
async def scprove(ctx):
await scprove_command(ctx.message)
TOKEN = open("../sus_bot_token.txt", 'r').read()
client.run(TOKEN)