mirror of
https://github.com/supleed2/gondilinabot-python.git
synced 2024-12-22 21:45:48 +00:00
Add message randomisation and ability to detect keywords within messages
This commit is contained in:
parent
552b7cbd89
commit
e130905194
27
main.py
27
main.py
|
@ -1,10 +1,13 @@
|
||||||
import discord
|
import discord
|
||||||
import re
|
import re
|
||||||
import yaml
|
import yaml
|
||||||
|
import random
|
||||||
|
|
||||||
# from discord.ext import commands
|
# from discord.ext import commands
|
||||||
|
|
||||||
bot = discord.Client()
|
bot = discord.Client()
|
||||||
|
sensitivity = 5
|
||||||
|
counter = random.randrange(0, sensitivity)
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
|
@ -12,8 +15,9 @@ async def on_ready():
|
||||||
print("Logged in as")
|
print("Logged in as")
|
||||||
print(bot.user.name + "#" + bot.user.discriminator)
|
print(bot.user.name + "#" + bot.user.discriminator)
|
||||||
print(bot.user.id)
|
print(bot.user.id)
|
||||||
await bot.change_presence(status=discord.Status.online,
|
await bot.change_presence(
|
||||||
activity=discord.Game(name="with Godlina"))
|
status=discord.Status.online, activity=discord.Game(name="with Godlina")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
|
@ -21,13 +25,19 @@ async def on_message(message):
|
||||||
if message.author == bot.user:
|
if message.author == bot.user:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
global counter
|
||||||
print("Message from " + message.author.name + ": " + message.content)
|
print("Message from " + message.author.name + ": " + message.content)
|
||||||
if message.content.startswith(
|
reply = re.split("I'm |Im |i'm |im |I am |i am ", message.content, 1)
|
||||||
("I'm", "Im", "i'm", "im", "I am", "i am")):
|
if len(reply) > 1:
|
||||||
reply = re.split("I'm |Im |i'm |im |I am |i am ",
|
if counter > 0:
|
||||||
message.content)[1]
|
counter -= 1
|
||||||
await message.reply("Hi " + reply + ", I'm Dad")
|
print("Cooldown: " + str(counter) + " messages")
|
||||||
|
else:
|
||||||
|
counter = random.randrange(0, sensitivity)
|
||||||
|
await message.reply("Hi " + reply[1] + ", I'm Dad")
|
||||||
print("Replied to " + message.author.name + " with Dad Joke")
|
print("Replied to " + message.author.name + " with Dad Joke")
|
||||||
|
else:
|
||||||
|
print("No match, ignoring...")
|
||||||
|
|
||||||
|
|
||||||
with open("secrets.yaml") as stream:
|
with open("secrets.yaml") as stream:
|
||||||
|
@ -38,4 +48,5 @@ with open("secrets.yaml") as stream:
|
||||||
print("Secrets.yaml failed to load, exiting...")
|
print("Secrets.yaml failed to load, exiting...")
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
# bot.run()
|
|
||||||
|
bot.run(secrets["bottoken"])
|
||||||
|
|
Loading…
Reference in a new issue