Fix auto-daily, other bugfixes.
This commit is contained in:
parent
84ad9ae165
commit
9da7137313
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"python.pythonPath": "venv\\Scripts\\python.exe"
|
||||||
|
}
|
14
src/bot.py
14
src/bot.py
@ -23,6 +23,8 @@ import os
|
|||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
|
from discord.ext import tasks
|
||||||
|
|
||||||
import central
|
import central
|
||||||
from handlers.command_logic import embed_builders
|
from handlers.command_logic import embed_builders
|
||||||
from handlers.commands import CommandHandler
|
from handlers.commands import CommandHandler
|
||||||
@ -36,7 +38,7 @@ config.read(dir_path + "/config.ini")
|
|||||||
class OrthoBot(discord.AutoShardedClient):
|
class OrthoBot(discord.AutoShardedClient):
|
||||||
def __init__(self, *args, loop=None, **kwargs):
|
def __init__(self, *args, loop=None, **kwargs):
|
||||||
super().__init__(*args, loop=loop, **kwargs)
|
super().__init__(*args, loop=loop, **kwargs)
|
||||||
self.bg_task = self.loop.create_task(self.run_dailies())
|
self.run_dailies.start()
|
||||||
self.current_page = None
|
self.current_page = None
|
||||||
self.total_pages = None
|
self.total_pages = None
|
||||||
|
|
||||||
@ -54,12 +56,10 @@ class OrthoBot(discord.AutoShardedClient):
|
|||||||
|
|
||||||
central.log_message("info", shard_id + 1, "global", "global", "connected")
|
central.log_message("info", shard_id + 1, "global", "global", "connected")
|
||||||
|
|
||||||
|
@tasks.loop(seconds=60.0)
|
||||||
async def run_dailies(self):
|
async def run_dailies(self):
|
||||||
await self.wait_until_ready()
|
await self.wait_until_ready()
|
||||||
|
|
||||||
while not self.is_closed():
|
|
||||||
# noinspection PyBroadException
|
|
||||||
try:
|
|
||||||
# a nice list comprehension for getting all the servers with daily stuff set
|
# a nice list comprehension for getting all the servers with daily stuff set
|
||||||
results = [x for x in central.guildDB.all() if "channel" in x and "time" in x]
|
results = [x for x in central.guildDB.all() if "channel" in x and "time" in x]
|
||||||
|
|
||||||
@ -72,13 +72,13 @@ class OrthoBot(discord.AutoShardedClient):
|
|||||||
|
|
||||||
if daily_time == current_time:
|
if daily_time == current_time:
|
||||||
embed = embed_builders.create_daily_embed()
|
embed = embed_builders.create_daily_embed()
|
||||||
|
|
||||||
|
try:
|
||||||
await channel.send("Here is today's daily readings and saints/feasts:")
|
await channel.send("Here is today's daily readings and saints/feasts:")
|
||||||
await channel.send(embed=embed)
|
await channel.send(embed=embed)
|
||||||
except Exception:
|
except discord.errors.Forbidden:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
await asyncio.sleep(60)
|
|
||||||
|
|
||||||
async def on_message(self, raw):
|
async def on_message(self, raw):
|
||||||
await self.wait_until_ready()
|
await self.wait_until_ready()
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ def run_command(command, args, user, guild, channel):
|
|||||||
"message": pages[0]
|
"message": pages[0]
|
||||||
}
|
}
|
||||||
elif command == "daily":
|
elif command == "daily":
|
||||||
return_embed = embed_builders.create_daily_embed(args[0])
|
return_embed = embed_builders.create_daily_embed(args[0] if args else None)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"level": "info",
|
"level": "info",
|
||||||
|
@ -46,16 +46,14 @@ def create_daily_embed(day="today"):
|
|||||||
elif day in dates:
|
elif day in dates:
|
||||||
date_formatted = f"{dates[day].month}/{dates[day].day}/{dates[day].year}"
|
date_formatted = f"{dates[day].month}/{dates[day].day}/{dates[day].year}"
|
||||||
daily = Daily(date_formatted)
|
daily = Daily(date_formatted)
|
||||||
else:
|
elif day is not None:
|
||||||
date_format = re.compile("[0-9]*\/[0-9]*\/[0-9]*")
|
date_format = re.compile("[0-9]*\/[0-9]*\/[0-9]*")
|
||||||
|
|
||||||
if date_format.match(day):
|
if date_format.match(day):
|
||||||
day = day[1:] if day.startswith("0") else day
|
day = day[1:] if day.startswith("0") else day
|
||||||
daily = Daily(day)
|
daily = Daily(day)
|
||||||
else:
|
else:
|
||||||
day = "random"
|
daily = Daily()
|
||||||
date_formatted = f"{dates[day].month}/{dates[day].day}/{dates[day].year}"
|
|
||||||
daily = Daily(date_formatted)
|
|
||||||
|
|
||||||
daily.get_data()
|
daily.get_data()
|
||||||
|
|
||||||
@ -95,13 +93,6 @@ def create_daily_embed(day="today"):
|
|||||||
else:
|
else:
|
||||||
embed.add_field(name=f"{saint.title} ({saint.id})", value="No information provided.", inline=False)
|
embed.add_field(name=f"{saint.title} ({saint.id})", value="No information provided.", inline=False)
|
||||||
|
|
||||||
name = "For more about today's saints and feasts"
|
|
||||||
|
|
||||||
if saints_to_display < len(daily.saints):
|
|
||||||
name += f" (including the remaining {str(len(daily.saints) - saints_to_display)})"
|
|
||||||
|
|
||||||
embed.add_field(name=f"{name}:", value=daily.public_url)
|
|
||||||
|
|
||||||
for reading in daily.readings:
|
for reading in daily.readings:
|
||||||
title = f"{reading.type_bb.title()} Reading ({reading.id}, {reading.event})"
|
title = f"{reading.type_bb.title()} Reading ({reading.id}, {reading.event})"
|
||||||
title = title.replace("Mg ", "Matins Gospel ")
|
title = title.replace("Mg ", "Matins Gospel ")
|
||||||
@ -148,22 +139,19 @@ def create_saint_embed(_id):
|
|||||||
|
|
||||||
_type += f" ({reading.id}, {saint.id})"
|
_type += f" ({reading.id}, {saint.id})"
|
||||||
|
|
||||||
embed.add_field(name=_type, value=reading.short_title, inline=True)
|
embed.add_field(name=_type, value=reading.short_title, inline=False)
|
||||||
|
|
||||||
for hymn in saint.hymns:
|
for hymn in saint.hymns:
|
||||||
embed.add_field(name=f"{hymn.short_title} ({hymn.tone})",
|
embed.add_field(name=f"{hymn.short_title} ({hymn.tone})",
|
||||||
value=f"© {hymn.translation.copyright} // {hymn.translation.body}", inline=False)
|
value=f"© {hymn.translation.copyright} // {hymn.translation.body}", inline=False)
|
||||||
|
|
||||||
name = "For more about this saint/feast"
|
|
||||||
embed.add_field(name=f"{name}:", value=saint.public_url, inline=False)
|
|
||||||
|
|
||||||
embed.set_footer(icon_url=central.icon, text=f"{central.version} | Greek Orthodox Archdiocese of America")
|
embed.set_footer(icon_url=central.icon, text=f"{central.version} | Greek Orthodox Archdiocese of America")
|
||||||
|
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
|
|
||||||
def create_lectionary_embed(_type, _id, event, _date=None):
|
def create_lectionary_embed(_type, _id, event, _date=None):
|
||||||
lectionary = Lectionary(_type, _id, event, date=_date)
|
lectionary = Lectionary(_type.upper(), _id, event, date=_date)
|
||||||
lectionary.get_data()
|
lectionary.get_data()
|
||||||
|
|
||||||
embed = discord.Embed()
|
embed = discord.Embed()
|
||||||
@ -179,9 +167,6 @@ def create_lectionary_embed(_type, _id, event, _date=None):
|
|||||||
reading_excerpt = textwrap.shorten(translation.body, width=600, placeholder="...")
|
reading_excerpt = textwrap.shorten(translation.body, width=600, placeholder="...")
|
||||||
embed.add_field(name=translation.short_title, value=reading_excerpt, inline=False)
|
embed.add_field(name=translation.short_title, value=reading_excerpt, inline=False)
|
||||||
|
|
||||||
name = "For more about this lectionary/reading"
|
|
||||||
embed.add_field(name=f"{name}:", value=lectionary.public_url, inline=False)
|
|
||||||
|
|
||||||
embed.set_footer(icon_url=central.icon, text=f"{central.version} | Greek Orthodox Archdiocese of America")
|
embed.set_footer(icon_url=central.icon, text=f"{central.version} | Greek Orthodox Archdiocese of America")
|
||||||
|
|
||||||
return embed
|
return embed
|
||||||
|
Loading…
Reference in New Issue
Block a user