286 lines
9.6 KiB
Python
286 lines
9.6 KiB
Python
import discord, time, random, os
|
|
from discord.ext import commands
|
|
|
|
|
|
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 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 = []
|
|
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, 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('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_command(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_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.addfield(name = "Well behaved", value="Bot will greet you back")
|
|
embed2.addfield(name = "Significant recognicition of sussynes", value = None)
|
|
embed2.addfield(name = "Word counting ability", value = None)
|
|
|
|
|
|
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('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
|
|
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('Detected sus from:', message.author.name, '(id:', message.author.id, ')')
|
|
t_s = time.time()
|
|
else:
|
|
pass
|
|
else:
|
|
pass
|
|
|
|
##############################################################################################################
|
|
##################################### FUNCTIONS AND COMMANDS HUB #############################################
|
|
##############################################################################################################
|
|
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", "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'] #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):
|
|
if message.author == client.user:
|
|
return
|
|
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)
|