diff --git a/1.2.5/bot.py b/1.2.5/bot.py new file mode 100644 index 0000000..854b22f --- /dev/null +++ b/1.2.5/bot.py @@ -0,0 +1,97 @@ +import discord +import time +import datetime +import configparser +import random +from discord.ext import tasks, commands +intents = discord.Intents.all() +client = discord.Client(intents=intents) +avgtimelst = [] +print("discord.py version") +print(discord.__version__) + + +#loading config files +botconf = configparser.ConfigParser() +botconf.read("config/bot.conf") +triggerbotconf = configparser.ConfigParser() +triggerbotconf.read("config/triggerbot.conf") +quotebotconf = configparser.ConfigParser() +quotebotconf.read("config/quotebot.conf") + + +#bot info +@client.event +async def on_ready(): + print('We have logged in as {0.user}'.format(client)) + if not dailyquote.is_running(): + dailyquote.start() + + +#main event +@client.event +async def on_message(message): + #defining variables + msg = str(message.content) + channel = str(message.channel.id) + author = str(message.author) + + + #reply to bots + if message.author.bot and botconf["config"]["replytobot"] == "false": + return + + + #start event timer + print("\n start client.event") + start = time.time() + + + #triggerbot + if triggerbotconf["config"]["enabled"] == "true": + x = 0 + found = "false" + triggersstr = (triggerbotconf["config"]["triggers"]) + triggers = triggersstr.split(",") + while x < len(triggers) and found == "false": + if triggers[x] not in msg: + x = x+1 + elif triggers[x] in msg: + found = "true" + replys = triggerbotconf["replys"][triggers[x]].split(",") + rand = random.randint(0,len(replys))-1 + await message.channel.send(replys[rand]) + else: + print("something happened") + + + #daily quote + if channel == quotebotconf["config"]["quotequeue"] and quotebotconf["config"]["enabled"] == "true": + file = open("data/quotes.var","a") + file.write(msg) + file.write(":") + file.close() + + + #end function timer + end = time.time() + reventime = str(round((end - start),3)) + avgtimelst.append(float(reventime)) + avgtime = str(sum(avgtimelst) / len(avgtimelst)) + print("\n end client.event \n time: " + str(reventime) + "\n average time: " + avgtime) + + +@tasks.loop(seconds=5,reconnect=True) +async def dailyquote(): + if quotebotconf["config"]["enabled"] == "true": + file = open("data/quotes.var","r+") + list = file.read().split(":") + rand = random.randint(0, (len(list)-1)) + print(rand) + channel = client.get_channel(int(quotebotconf["config"]["dailyquote"])) + await channel.send(list[rand]) + list.remove(rand) + file.write(list) + + +client.run(botconf["config"]["token"]) diff --git a/1.2.5/config/bot.conf b/1.2.5/config/bot.conf new file mode 100644 index 0000000..b5491cc --- /dev/null +++ b/1.2.5/config/bot.conf @@ -0,0 +1,7 @@ +[config] +token = OTg2NDA4MjM3Njg5NjMwNzYx.Gn3sV3.af4MeWrAct-e6FyN6oDWt-QaOfOHuYBY97Vw7k +replytobot = false + +[modules] +triggerbot = "true" +quotebot = "true" diff --git a/1.2.5/config/quotebot.conf b/1.2.5/config/quotebot.conf new file mode 100644 index 0000000..60da3e6 --- /dev/null +++ b/1.2.5/config/quotebot.conf @@ -0,0 +1,4 @@ +[config] +enabled = true +quotequeue = 1010042640508669982 +dailyquote = 1004178748205187086 diff --git a/1.2.5/config/triggerbot.conf b/1.2.5/config/triggerbot.conf new file mode 100644 index 0000000..168a235 --- /dev/null +++ b/1.2.5/config/triggerbot.conf @@ -0,0 +1,8 @@ +[config] +enabled = true +blacklist = 1234567890,0987654321 #blacklisted channels +triggers = hello,howdy +[replys] +hello = hello,hi +howdy = howdy + diff --git a/1.2.5/data/quotes.var b/1.2.5/data/quotes.var new file mode 100644 index 0000000..add1495 --- /dev/null +++ b/1.2.5/data/quotes.var @@ -0,0 +1 @@ +joe mama -ian:joe mama -eric:avergae man -peter:hello:a:a:a:a:a:a:a:a:a:hello:hello: \ No newline at end of file diff --git a/1.2.5/test b/1.2.5/test new file mode 100644 index 0000000..e8b0ce1 --- /dev/null +++ b/1.2.5/test @@ -0,0 +1,10 @@ +import schedule +import time +def test(): + print("deez") +schedule.every(1).minutes.do(test) +while 1 == 1: + print("joe") + time.sleep(5) + schedule.run_pending() +