made progress
This commit is contained in:
parent
f604d1dad8
commit
6d74466432
4
config_example/random_messages.txt
Normal file
4
config_example/random_messages.txt
Normal file
@ -0,0 +1,4 @@
|
||||
a list of random messages
|
||||
bot will occasionally send
|
||||
every new line is a new type of message
|
||||
the message is randomly chosen
|
4
config_example/random_responses.txt
Normal file
4
config_example/random_responses.txt
Normal file
@ -0,0 +1,4 @@
|
||||
just a list of random responses
|
||||
bot will occasionally send these as a reply to a message
|
||||
every new line is a new type of message
|
||||
the message is randomly chosen
|
2
config_example/responses/example_obsahuje.txt
Normal file
2
config_example/responses/example_obsahuje.txt
Normal file
@ -0,0 +1,2 @@
|
||||
example; priklad
|
||||
spotnul jsem example lol; toto je example; tato zprava obsahuje example
|
7
config_example/responses/name_where.txt
Normal file
7
config_example/responses/name_where.txt
Normal file
@ -0,0 +1,7 @@
|
||||
if; any; of; theese; words; are; placed; as; specified; in; the; message
|
||||
bot; will; choose; random; of; these; words
|
||||
|
||||
#! here in directory config/responses are groups of responses
|
||||
#! the first row are words bot will search for in a message and the second are words bot will choose one from and send as reply message
|
||||
#! "name" is the name of group, and "where" is location in the message of searched words as condition, it can be "zacatek"/"konec"/"obsahuje"
|
||||
#! the count of theese files is not limited
|
@ -1,38 +1,69 @@
|
||||
import discord, random
|
||||
from discord.ext import commands
|
||||
import responses # type: ignore
|
||||
from discord.ext import commands, tasks
|
||||
|
||||
### Karlovy funkce
|
||||
import responses_messages
|
||||
|
||||
### Karluv config
|
||||
|
||||
prefix = "Karle "
|
||||
client = commands.Bot(command_prefix=prefix, intents=discord.Intents.all())
|
||||
|
||||
#
|
||||
#
|
||||
############################################################################bot login
|
||||
################################################################################
|
||||
############################### LOOPS AND READY ################################
|
||||
################################################################################
|
||||
|
||||
### chat participation loop
|
||||
@tasks.loop(minutes = 10)
|
||||
async def loop_chat_message():
|
||||
if random.randrange(0,1000) == random.randrange(0,1000):
|
||||
await client.get_channel(834034469152882729).send(responses_messages.get_random_message())
|
||||
else:
|
||||
pass
|
||||
|
||||
### ready event
|
||||
@client.event
|
||||
async def on_ready():
|
||||
print(f"[ONREADY ] logged in as: {client.user}")
|
||||
#myloop.start()
|
||||
#
|
||||
#
|
||||
############################################################################ on message event
|
||||
|
||||
loop_chat_message.start()
|
||||
|
||||
################################################################################
|
||||
############################## ON MESSAGE EVENT ################################
|
||||
################################################################################
|
||||
@client.event
|
||||
async def on_message(message):
|
||||
#reply chance
|
||||
if message.author != client.user and message.content.startswith(prefix) == False and random.randint(1,1) == random.randint(1,1):
|
||||
odpoved = responses.response_generator(message.content)
|
||||
|
||||
### chance to add reaction to the message
|
||||
if random.randint(1,120) == random.randint(1,120):
|
||||
await message.add_reaction("❤️")
|
||||
|
||||
### reply to mention
|
||||
if client.user.mentioned_in(message) and "@here" not in message.content and random.randint(1,3) == random.randint(1,3):
|
||||
odpoved = responses_messages.response_generator(message)
|
||||
if odpoved != None:
|
||||
await message.reply(odpoved)
|
||||
|
||||
### every message reply chance
|
||||
elif message.author != client.user and message.content.startswith(prefix) == False and random.randint(1,60) == random.randint(1,60):
|
||||
odpoved = responses_messages.response_generator(message)
|
||||
if odpoved != None:
|
||||
await message.reply(odpoved)
|
||||
|
||||
|
||||
|
||||
await client.process_commands(message)
|
||||
#
|
||||
#
|
||||
############################################################################pomoc command "Karle pomoc"
|
||||
|
||||
################################################################################
|
||||
################################ POMOC COMMAND #################################
|
||||
################################################################################
|
||||
@client.command()
|
||||
async def pomoc(ctx):
|
||||
await ctx.send("susik")
|
||||
|
||||
|
||||
await ctx.send("Jsem pátý člen vašeho serveru a občas něco napíšu <3, nějaké info najdeš i v mém profilu")
|
||||
|
||||
################################################################################
|
||||
################################################################################
|
||||
################################################################################
|
||||
|
||||
TOKEN = open("config/token.txt", 'r').read()
|
||||
client.run(TOKEN)
|
||||
|
62
responses.py
62
responses.py
@ -1,62 +0,0 @@
|
||||
import random, os
|
||||
|
||||
def Response_type_determinator(response_type_dict, msg_content):
|
||||
for type in response_type_dict.values():
|
||||
for slovo in type.slova:
|
||||
if type.fn_podminka(slovo, msg_content) == True:
|
||||
return(random.choice(type.responses))
|
||||
|
||||
|
||||
class Response():
|
||||
def __init__(self, slova, podminka, responses):
|
||||
self.slova = slova
|
||||
self.podminka = podminka
|
||||
self.responses = responses
|
||||
|
||||
def fn_podminka(self, slovo, msg_content):
|
||||
if self.podminka == "obsahuje":
|
||||
return(slovo in msg_content)
|
||||
|
||||
elif self.podminka == "konec":
|
||||
return(msg_content.endswith(slovo))
|
||||
|
||||
elif self.podminka == "zacatek":
|
||||
return(msg_content.startswith(slovo))
|
||||
|
||||
def get_response_types():
|
||||
directory = os.walk("config/responses")
|
||||
response_dict = {}
|
||||
|
||||
for paths in directory:
|
||||
for path in paths[2]:
|
||||
|
||||
content = open(f"config/responses/{path}", "r").readlines()
|
||||
slova = content[0].split(", ")
|
||||
responses = content[1].split(", ")
|
||||
|
||||
path = path[:-4].split("_")
|
||||
value = path[0]
|
||||
podminka = path[1]
|
||||
|
||||
response_dict[value] = Response(slova, podminka, responses)
|
||||
|
||||
return(response_dict)
|
||||
|
||||
|
||||
mista = Response(["kde", "where"], "zacatek", ["tady", "tam", "tam ne", "tamhle"])
|
||||
cas = Response(["kdy", "v kolik", "when"], "zacatek", ["ted ne", "nikdy", "ve 12:00", "zitra", "dnes vecer", "v 9"])
|
||||
|
||||
response_types = [mista, cas]
|
||||
|
||||
|
||||
def response_generator(msg_content):
|
||||
moznosti = ["determinator"]
|
||||
x = random.choice(moznosti)
|
||||
|
||||
if x == "determinator":
|
||||
odpoved = Response_type_determinator(get_response_types(), msg_content)
|
||||
|
||||
else:
|
||||
return(None)
|
||||
|
||||
return(odpoved)
|
86
responses_messages.py
Normal file
86
responses_messages.py
Normal file
@ -0,0 +1,86 @@
|
||||
import random, os
|
||||
|
||||
###############################################################################
|
||||
###################### TYPY ODPOVEDI PODLE PODMINEK ###########################
|
||||
###############################################################################
|
||||
def Response_type_determinator(response_type_dict, msg_content):
|
||||
for type in response_type_dict.values():
|
||||
for slovo in type.slova:
|
||||
if type.fn_podminka(slovo, msg_content) == True:
|
||||
return(random.choice(type.responses))
|
||||
|
||||
|
||||
class Response():
|
||||
def __init__(self, slova, podminka, responses):
|
||||
self.slova = slova
|
||||
self.podminka = podminka
|
||||
self.responses = responses
|
||||
|
||||
def fn_podminka(self, slovo, msg_content):
|
||||
if self.podminka == "obsahuje":
|
||||
return(slovo in msg_content)
|
||||
|
||||
elif self.podminka == "konec":
|
||||
return(msg_content.endswith(slovo))
|
||||
|
||||
elif self.podminka == "zacatek":
|
||||
return(msg_content.startswith(slovo))
|
||||
|
||||
|
||||
def get_responses():
|
||||
directory = os.walk("config/responses")
|
||||
response_dict = {}
|
||||
|
||||
for paths in directory:
|
||||
for path in paths[2]:
|
||||
|
||||
content = open(f"config/responses/{path}", "r", encoding="utf-8").readlines()
|
||||
slova = content[0][:-1].split("; ") #[:-1] kvuli \n
|
||||
responses = content[1].split("; ")
|
||||
|
||||
path = path[:-4].split("_")
|
||||
value = path[0]
|
||||
podminka = path[1]
|
||||
|
||||
response_dict[value] = Response(slova, podminka, responses)
|
||||
|
||||
return(response_dict)
|
||||
################################################################################
|
||||
############################## NAHODNA ODPOVED #################################
|
||||
################################################################################
|
||||
|
||||
def get_random_response():
|
||||
content = open("config/random_responses.txt", "r", encoding="utf-8").read().splitlines()
|
||||
return(random.choice(content))
|
||||
|
||||
################################################################################
|
||||
###################### GENERATOR ODPOVEDI Z MOZNOSTI ###########################
|
||||
################################################################################
|
||||
|
||||
def response_generator(msg):
|
||||
odpoved = Response_type_determinator(get_responses(), msg.content)
|
||||
if odpoved == None:
|
||||
odpoved = get_random_response()
|
||||
return(odpoved)
|
||||
|
||||
# moznosti = ["determinator"]
|
||||
# x = random.choice(moznosti)
|
||||
#
|
||||
# if x == "determinator":
|
||||
# odpoved = Response_type_determinator(get_responses(), msg.content)
|
||||
#
|
||||
# if x == "nahodna_odpoved":
|
||||
# odpoved = get_random_response()
|
||||
#
|
||||
# else:
|
||||
# odpoved = get_random_response()
|
||||
#
|
||||
# return(odpoved)
|
||||
|
||||
################################################################################
|
||||
############################# NAHODNA ZPRAVA ###################################
|
||||
################################################################################
|
||||
|
||||
def get_random_message():
|
||||
content = open("config/random_messages.txt", "r", encoding="utf-8").read().splitlines()
|
||||
return(random.choice(content))
|
Loading…
Reference in New Issue
Block a user