This commit is contained in:
ionburger 2022-11-08 14:39:10 -07:00
parent 67494b82b8
commit f3ccad70cf
3 changed files with 94 additions and 89 deletions

View File

@ -1,5 +1,6 @@
#imports #imports
import version import version
import main
import sys import sys
import os import os
import configparser import configparser
@ -32,3 +33,7 @@ if config["config"]["autoupdate"] == "true":
os.execl(sys.executable, sys.executable, *sys.argv) os.execl(sys.executable, sys.executable, *sys.argv)
else: else:
print("running latest version of turdbot",versionl) print("running latest version of turdbot",versionl)
else:
print("autoupdate disabled")
main.run()

View File

@ -9,100 +9,102 @@ import datetime
import datetime import datetime
import shelve import shelve
import backports.zoneinfo as zoneinfo import backports.zoneinfo as zoneinfo
from py.storage import config from storage import config
import version
from discord import app_commands from discord import app_commands
from discord.ext import tasks, commands from discord.ext import tasks, commands
def run():
quotetime = datetime.time(hour=12, tzinfo=zoneinfo.ZoneInfo("MST")) quotetime = datetime.time(hour=12, tzinfo=zoneinfo.ZoneInfo("MST"))
avgtimelst = [] avgtimelst = []
token = open("py/TOKEN", "r").read() token = open("TOKEN", "r").read()
intents = discord.Intents.all() intents = discord.Intents.all()
bot = commands.Bot(intents=intents, command_prefix=".") bot = commands.Bot(intents=intents, command_prefix=".")
# on ready # on ready
@bot.event @bot.event
async def on_ready(): async def on_ready():
print('We have logged in as {0.user}'.format(bot)) print('logged in as {0.user}'.format(bot))
if not dailyquote.is_running(): print("discord.py version",discord.__version__)
dailyquote.start() print("turdbot version",version.local())
print(bot.tree)
print("discord.py version") if not dailyquote.is_running():
print(discord.__version__) dailyquote.start()
@bot.hybrid_command(name="eee", with_app_command=True) @bot.hybrid_command(name="eee", with_app_command=True)
async def foo(ctx): async def foo(ctx):
for guild in bot.guilds: for guild in bot.guilds:
await ctx.send(guild.id) await ctx.send(guild.id)
# main event # main event
@bot.event @bot.event
async def on_message(message): async def on_message(message):
# defining variables # defining variables
msg = str(message.content) msg = str(message.content)
channel = str(message.channel.id) channel = str(message.channel.id)
server = message.guild.id server = message.guild.id
author = str(message.author) author = str(message.author)
# reply to bots # reply to bots
if message.author.bot and config("replytobot") == "false": if message.author.bot and config("replytobot") == "false":
return return
# start event timer # start event timer
print("\n start client.event") print("\n start client.event")
start = datetime.datetime.now() start = datetime.datetime.now()
# triggerbot # triggerbot
if config("triggerbotenabled") == "true": if config("triggerbotenabled") == "true":
x = 0 x = 0
found = "false" found = "false"
triggers = config("triggerbottriggers", db="data") triggers = config("triggerbottriggers", db="data")
while x < len(triggers) and found == "false": while x < len(triggers) and found == "false":
if triggers[x] not in msg: if triggers[x] not in msg:
x = x+1 x = x+1
elif triggers[x] in msg: elif triggers[x] in msg:
found = "true" found = "true"
replys = config(triggerbotreplys, db=data) replys = config(triggerbotreplys, db=data)
rand = random.randint(0, len(replys))-1 rand = random.randint(0, len(replys))-1
await message.channel.send(replys[rand]) await message.channel.send(replys[rand])
else: else:
print("something happened") print("something happened")
# daily quote # daily quote
if channel == config("quotequeue") and config("quotebotenabled") == "true": if channel == config("quotequeue") and config("quotebotenabled") == "true":
file = open("data/quotes.var", "a") file = open("data/quotes.var", "a")
file.write(msg) file.write(msg)
file.write(":") file.write(":")
file.close() file.close()
# bot commands # bot commands
await bot.process_commands(message) await bot.process_commands(message)
# end function timer # end function timer
end = datetime.datetime.now() end = datetime.datetime.now()
eventime = (end - start) eventime = (end - start)
microseconds = eventime.microseconds microseconds = eventime.microseconds
avgtimelst.append(microseconds) avgtimelst.append(microseconds)
avgtime = sum(avgtimelst) / len(avgtimelst) avgtime = sum(avgtimelst) / len(avgtimelst)
print("\n end client.event \n microseconds: " + print("\n end client.event \n microseconds: " +
str(microseconds) + "\n average time: " + str(avgtime)) str(microseconds) + "\n average time: " + str(avgtime))
@tasks.loop(time=quotetime, reconnect=True) @tasks.loop(time=quotetime, reconnect=True)
async def dailyquote(): async def dailyquote():
if config("quotebotenabled") == "true": if config("quotebotenabled") == "true":
file = open("data/quotes.var", "r+") file = open("data/quotes.var", "r+")
list = file.read().split(":") list = file.read().split(":")
rand = random.randint(0, (len(list)-1)) rand = random.randint(0, (len(list)-1))
print(rand) print(rand)
channel = bot.get_channel(int(quotebotconf["config"]["dailyquote"])) channel = bot.get_channel(int(quotebotconf["config"]["dailyquote"]))
await channel.send(list.pop(rand)) await channel.send(list.pop(rand))
file.write(":".join(list)) file.write(":".join(list))
file.close() file.close()
bot.run(token) bot.run(token)

View File

@ -15,16 +15,14 @@ def config(value,db="config",serverid=server,mode="r"):
} }
data = shelve.open("bot.shlf",writeback=True) with shelve.open("bot.shlf",writeback=True) as data:
if mode == "r": if mode == "r":
try: try:
return data[db][serverid][value] return data[db][serverid][value]
except: except:
return default[value] return default[value]
elif mode == "w": elif mode == "w":
data[db][serverid] = value data[db][serverid] = value
return("success") return("success")
else: else:
print("error") print("error")
data.close()