async def newsSubscription(client, message): p = DictionaryReader() if not message.guild: return targetRole = '{0}News'.format(message.content[5::].capitalize()) print(targetRole) role = utils.find(lambda r: r.name == targetRole, message.author.guild.roles) # Role Desired doesn't exist if not role: await message.author.send( 'Invalid subscription name. Valid subscriptions are:\n{0}'. format(p.readEntry('validsubscriptions', ''))) else: # Doesn't have the role already if role not in message.author.roles: await message.author.add_roles( role, reason='Subscribed to {0}'.format(targetRole)) await message.author.send( p.readEntry('newssubscriptionadd', '').format(targetRole)) # Already has the role, unsubscribing else: await message.author.remove_roles( role, reason='Unsubscribed to {0}'.format(targetRole)) await message.author.send( p.readEntry('newssubscriptionremove', '').format(targetRole))
async def on_raw_reaction_add(payload): if payload.user_id == client.user.id: return r = DictionaryReader() print(r.readEntry('subscriptionchannel','')) print(payload.emoji.name) #Only for reactions inside the report channel if payload.channel_id == int(r.perspectiveLogChannel()): await toxicity.feedback(payload.emoji, payload.user_id, r) elif payload.channel_id == int(r.readEntry('subscriptionchannel','')): await RoleHandler.newsSubscriptionAdd(client, payload.emoji, payload.user_id, payload.guild_id)
async def on_raw_reaction_remove(payload): r = DictionaryReader() if payload.channel_id == int(r.readEntry('subscriptionchannel', '')): await RoleHandler.newsSubscriptionRemove(client, payload.emoji, payload.user_id, payload.guild_id)
async def newsSubscriptionRemove(client, emoji, user_id, guild_id): if not emoji.is_custom_emoji(): return targetRole = '{0}News'.format(emoji.name.capitalize()) print(targetRole) guild = client.get_guild(guild_id) role = utils.find(lambda r: r.name == targetRole, guild.roles) if not role: return member = guild.get_member(user_id) p = DictionaryReader() if role in member.roles: await member.remove_roles( role, reason='Unsubscribed to {0}'.format(targetRole)) await member.send( p.readEntry('newssubscriptionremove', '').format(targetRole))