Fixes after rebase
This commit is contained in:
parent
d7852c2307
commit
5d43842e3c
3 changed files with 42 additions and 20 deletions
|
@ -61,13 +61,21 @@ bot.config = config
|
|||
bot.script_name = script_name
|
||||
bot.wanted_jsons = wanted_jsons
|
||||
|
||||
async def get_channel_safe(self, id):
|
||||
res = self.get_channel(id)
|
||||
if res is None:
|
||||
res = await self.fetch_channel(id)
|
||||
|
||||
return res
|
||||
|
||||
commands.Bot.get_channel_safe = get_channel_safe
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
aioh = {"User-Agent": f"{script_name}/1.0'"}
|
||||
bot.aiosession = aiohttp.ClientSession(headers=aioh)
|
||||
bot.app_info = await bot.application_info()
|
||||
bot.botlog_channel = bot.get_channel(config.botlog_channel)
|
||||
bot.botlog_channel = await bot.get_channel_safe(config.botlog_channel)
|
||||
|
||||
log.info(
|
||||
f"\nLogged in as: {bot.user.name} - "
|
||||
|
@ -107,7 +115,7 @@ async def on_command(ctx):
|
|||
|
||||
@bot.event
|
||||
async def on_error(event_method, *args, **kwargs):
|
||||
log.error(f"Error on {event_method}: {sys.exc_info()}")
|
||||
log.exception(f"Error on {event_method}:")
|
||||
|
||||
|
||||
@bot.event
|
||||
|
|
|
@ -24,7 +24,7 @@ class Robocronp(Cog):
|
|||
async def send_data(self):
|
||||
await self.bot.wait_until_ready()
|
||||
data_files = [discord.File(fpath) for fpath in self.bot.wanted_jsons]
|
||||
log_channel = self.bot.get_channel(config.botlog_channel)
|
||||
log_channel = await self.bot.get_channel_safe(config.botlog_channel)
|
||||
await log_channel.send("Hourly data backups:", files=data_files)
|
||||
|
||||
@commands.guild_only()
|
||||
|
@ -62,7 +62,7 @@ class Robocronp(Cog):
|
|||
|
||||
async def do_jobs(self, ctab, jobtype, timestamp):
|
||||
await self.bot.wait_until_ready()
|
||||
log_channel = self.bot.get_channel(config.botlog_channel)
|
||||
log_channel = await self.bot.get_channel_safe(config.botlog_channel)
|
||||
for job_name in ctab[jobtype][timestamp]:
|
||||
try:
|
||||
job_details = ctab[jobtype][timestamp][job_name]
|
||||
|
@ -101,8 +101,8 @@ class Robocronp(Cog):
|
|||
|
||||
async def clean_channel(self, channel_id):
|
||||
await self.bot.wait_until_ready()
|
||||
log_channel = self.bot.get_channel(config.botlog_channel)
|
||||
channel = self.bot.get_channel(channel_id)
|
||||
log_channel = await self.bot.get_channel_safe(config.botlog_channel)
|
||||
channel = await self.bot.get_channel_safe(channel_id)
|
||||
try:
|
||||
done_cleaning = False
|
||||
count = 0
|
||||
|
@ -123,7 +123,7 @@ class Robocronp(Cog):
|
|||
@tasks.loop(minutes=1)
|
||||
async def minutely(self):
|
||||
await self.bot.wait_until_ready()
|
||||
log_channel = self.bot.get_channel(config.botlog_channel)
|
||||
log_channel = await self.bot.get_channel_safe(config.botlog_channel)
|
||||
try:
|
||||
ctab = get_crontab()
|
||||
timestamp = time.time()
|
||||
|
@ -144,7 +144,7 @@ class Robocronp(Cog):
|
|||
@tasks.loop(hours=1)
|
||||
async def hourly(self):
|
||||
await self.bot.wait_until_ready()
|
||||
log_channel = self.bot.get_channel(config.botlog_channel)
|
||||
log_channel = await self.bot.get_channel_safe(config.botlog_channel)
|
||||
try:
|
||||
await self.send_data()
|
||||
# Handle clean channels
|
||||
|
@ -159,11 +159,11 @@ class Robocronp(Cog):
|
|||
@tasks.loop(hours=24)
|
||||
async def daily(self):
|
||||
await self.bot.wait_until_ready()
|
||||
log_channel = self.bot.get_channel(config.botlog_channel)
|
||||
log_channel = await self.bot.get_channel_safe(config.botlog_channel)
|
||||
try:
|
||||
# Reset verification and algorithm
|
||||
if "cogs.verification" in config.initial_cogs:
|
||||
verif_channel = self.bot.get_channel(config.welcome_channel)
|
||||
verif_channel = await self.bot.get_channel_safe(config.welcome_channel)
|
||||
await self.bot.do_resetalgo(verif_channel, "daily robocronp")
|
||||
except:
|
||||
# Don't kill cronjobs if something goes wrong.
|
||||
|
|
|
@ -114,14 +114,18 @@ class RyujinxReactionRoles(Cog):
|
|||
async def handle_offline_reaction_add(self):
|
||||
await self.bot.wait_until_ready()
|
||||
for reaction in self.m.reactions:
|
||||
for user in await reaction.users().flatten():
|
||||
reactions_users = []
|
||||
async for user in reaction.users():
|
||||
reactions_users.append(user)
|
||||
|
||||
for user in reactions_users:
|
||||
emoji_name = str(reaction.emoji)
|
||||
if emoji_name[0] == "<":
|
||||
emoji_name = emoji_name[1:-1]
|
||||
|
||||
if self.get_role_from_emoji(emoji_name) is not None:
|
||||
role = self.get_role(emoji_name)
|
||||
if not user in role.members and not user.bot:
|
||||
if not user in role.members and not user.bot and type(user) is discord.Member:
|
||||
await user.add_roles(role)
|
||||
else:
|
||||
await self.m.clear_reaction(reaction.emoji)
|
||||
|
@ -134,10 +138,16 @@ class RyujinxReactionRoles(Cog):
|
|||
if emoji_name[0] == "<":
|
||||
emoji_name = emoji_name[1:-1]
|
||||
|
||||
reactions_users = []
|
||||
async for user in reaction.users():
|
||||
reactions_users.append(user)
|
||||
|
||||
role = self.get_role(emoji_name)
|
||||
for user in role.members:
|
||||
if user not in await reaction.users().flatten():
|
||||
await self.m.guild.get_member(user.id).remove_roles(role)
|
||||
if user not in reactions_users:
|
||||
member = self.m.guild.get_member(user.id)
|
||||
if member is not None:
|
||||
await member.remove_roles(role)
|
||||
|
||||
def load_reaction_config(self):
|
||||
if not os.path.exists(self.file):
|
||||
|
@ -164,9 +174,14 @@ class RyujinxReactionRoles(Cog):
|
|||
guild = self.bot.guilds[0] # The ryu guild in which the bot is.
|
||||
channel = guild.get_channel(self.channel_id)
|
||||
|
||||
m = discord.utils.get(
|
||||
await channel.history().flatten(), id=self.reaction_config["id"]
|
||||
)
|
||||
if channel is None:
|
||||
channel = await guild.fetch_channel(self.channel_id)
|
||||
|
||||
history = []
|
||||
async for msg in channel.history():
|
||||
history.append(msg)
|
||||
|
||||
m = discord.utils.get(history, id=self.reaction_config["id"])
|
||||
if m is None:
|
||||
self.reaction_config["id"] = None
|
||||
|
||||
|
@ -183,9 +198,7 @@ class RyujinxReactionRoles(Cog):
|
|||
await self.handle_offline_reaction_remove()
|
||||
|
||||
else:
|
||||
self.m = discord.utils.get(
|
||||
await channel.history().flatten(), id=self.reaction_config["id"]
|
||||
)
|
||||
self.m = m
|
||||
self.msg_id = self.m.id
|
||||
|
||||
await self.m.edit(embed=await self.generate_embed())
|
||||
|
@ -199,6 +212,7 @@ class RyujinxReactionRoles(Cog):
|
|||
|
||||
@Cog.listener()
|
||||
async def on_ready(self):
|
||||
await self.bot.wait_until_ready()
|
||||
self.reaction_config = self.load_reaction_config()
|
||||
|
||||
await self.reload_reaction_message()
|
||||
|
|
Loading…
Reference in a new issue