More 3.4 compatibility, mentions and listeners

pull/121/head
bobloy 4 years ago
parent 3d4a6578fd
commit 151eca1c76

@ -254,6 +254,9 @@ class CCRole(commands.Cog):
if len(message.content) < 2 or is_private or not user_allowed or message.author.bot: if len(message.content) < 2 or is_private or not user_allowed or message.author.bot:
return return
if await self.bot.cog_disabled_in_guild(self, message.guild):
return
ctx = await self.bot.get_context(message) ctx = await self.bot.get_context(message)
if ctx.prefix is None: if ctx.prefix is None:
@ -273,28 +276,6 @@ class CCRole(commands.Cog):
if cmd is not None: if cmd is not None:
await self.eval_cc(cmd, message, ctx) await self.eval_cc(cmd, message, ctx)
# @commands.Cog.listener()
# async def on_message(self, message: discord.Message):
# if len(message.content) < 2 or message.guild is None:
# return
#
# ctx: commands.Context = await self.bot.get_context(message)
# cmd = ctx.invoked_with
# guild = message.guild
# # try:
# # prefix = await self.get_prefix(message)
# # except ValueError:
# # return
#
# # prefix = ctx.prefix
#
# cmdlist = self.config.guild(guild).cmdlist
# # cmd = message.content[len(prefix) :].split()[0].lower()
# cmd = await cmdlist.get_raw(cmd, default=None)
#
# if cmd is not None:
# await self.eval_cc(cmd, message, ctx)
async def _get_roles_from_content(self, ctx, content): async def _get_roles_from_content(self, ctx, content):
content_list = content.split(",") content_list = content.split(",")
try: try:
@ -325,7 +306,7 @@ class CCRole(commands.Cog):
return p return p
raise ValueError raise ValueError
async def eval_cc(self, cmd, message, ctx): async def eval_cc(self, cmd, message: discord.Message, ctx: commands.Context):
"""Does all the work""" """Does all the work"""
if cmd["proles"] and not ( if cmd["proles"] and not (
set(role.id for role in message.author.roles) & set(cmd["proles"]) set(role.id for role in message.author.roles) & set(cmd["proles"])
@ -400,7 +381,7 @@ class CCRole(commands.Cog):
await message.channel.send("Permission error: Unable to remove roles") await message.channel.send("Permission error: Unable to remove roles")
out_message = self.format_cc(cmd, message, target) out_message = self.format_cc(cmd, message, target)
await message.channel.send(out_message) await message.channel.send(out_message, allowed_mentions=discord.AllowedMentions())
def format_cc(self, cmd, message, target): def format_cc(self, cmd, message, target):
out = cmd["text"] out = cmd["text"]

@ -427,6 +427,9 @@ class Chatter(Cog):
if len(message.content) < 2 or is_private or not user_allowed or message.author.bot: if len(message.content) < 2 or is_private or not user_allowed or message.author.bot:
return return
if await self.bot.cog_disabled_in_guild(self, message.guild):
return
ctx: commands.Context = await self.bot.get_context(message) ctx: commands.Context = await self.bot.get_context(message)
if ctx.prefix is not None: if ctx.prefix is not None:

@ -89,6 +89,9 @@ class Dad(Cog):
if guild is None: if guild is None:
return return
if await self.bot.cog_disabled_in_guild(self, guild):
return
guild_config = self.config.guild(guild) guild_config = self.config.guild(guild)
is_on = await guild_config.enabled() is_on = await guild_config.enabled()
if not is_on: if not is_on:
@ -113,7 +116,8 @@ class Dad(Cog):
else: else:
out = cleaned_content[4:] out = cleaned_content[4:]
try: try:
await message.channel.send(f"Hi {out}, I'm {guild.me.display_name}!") await message.channel.send(f"Hi {out}, I'm {guild.me.display_name}!",
allowed_mentions=discord.AllowedMentions)
except discord.HTTPException: except discord.HTTPException:
return return

@ -97,6 +97,9 @@ class ExclusiveRole(Cog):
if before.roles == after.roles: if before.roles == after.roles:
return return
if await self.bot.cog_disabled_in_guild(self, after.guild):
return
await asyncio.sleep(1) await asyncio.sleep(1)
role_set = set(await self.config.guild(after.guild).role_list()) role_set = set(await self.config.guild(after.guild).role_list())

@ -1,5 +1,6 @@
import asyncio import asyncio
import discord
from discord.utils import get from discord.utils import get
from redbot.core import Config, checks, commands from redbot.core import Config, checks, commands
from redbot.core.bot import Red from redbot.core.bot import Red
@ -38,8 +39,18 @@ class ForceMention(Cog):
if not role_obj.mentionable: if not role_obj.mentionable:
await role_obj.edit(mentionable=True) await role_obj.edit(mentionable=True)
await ctx.send("{}\n{}".format(role_obj.mention, message)) await ctx.send(
"{}\n{}".format(role_obj.mention, message),
allowed_mentions=discord.AllowedMentions(
everyone=False, users=False, roles=[role_obj]
),
)
await asyncio.sleep(5) await asyncio.sleep(5)
await role_obj.edit(mentionable=False) await role_obj.edit(mentionable=False)
else: else:
await ctx.send("{}\n{}".format(role_obj.mention, message)) await ctx.send(
"{}\n{}".format(role_obj.mention, message),
allowed_mentions=discord.AllowedMentions(
everyone=False, users=False, roles=[role_obj]
),
)

@ -2,7 +2,7 @@
"author": [ "author": [
"Bobloy" "Bobloy"
], ],
"min_bot_version": "3.3.0", "min_bot_version": "3.4.0",
"description": "Mentions roles that are unmentionable", "description": "Mentions roles that are unmentionable",
"hidden": false, "hidden": false,
"install_msg": "Thank you for installing ForceMention! Get started with `[p]load forcemention`, then `[p]forcemention`", "install_msg": "Thank you for installing ForceMention! Get started with `[p]load forcemention`, then `[p]forcemention`",

@ -1,5 +1,6 @@
from collections import defaultdict from collections import defaultdict
from random import randint from random import randint
from typing import Union
import discord import discord
from redbot.core import Config, checks, commands from redbot.core import Config, checks, commands
@ -280,15 +281,22 @@ class Hangman(Cog):
await self._reprintgame(message) await self._reprintgame(message)
@commands.Cog.listener() @commands.Cog.listener()
async def on_react(self, reaction, user): async def on_react(self, reaction, user: Union[discord.User, discord.Member]):
""" Thanks to flapjack reactpoll for guidelines """ Thanks to flapjack reactpoll for guidelines
https://github.com/flapjax/FlapJack-Cogs/blob/master/reactpoll/reactpoll.py""" https://github.com/flapjax/FlapJack-Cogs/blob/master/reactpoll/reactpoll.py"""
guild: discord.Guild = getattr(user, "guild", None)
if guild is None:
return
if reaction.message.id != self.the_data[guild]["trackmessage"]:
return
if user.bot:
return # Don't react to bot reactions
if reaction.message.id != self.the_data[user.guild]["trackmessage"]: if await self.bot.cog_disabled_in_guild(self, guild):
return return
if user == self.bot.user:
return # Don't react to bot's own reactions
message = reaction.message message = reaction.message
emoji = reaction.emoji emoji = reaction.emoji

@ -273,14 +273,20 @@ class InfoChannel(Cog):
@Cog.listener() @Cog.listener()
async def on_member_join(self, member: discord.Member): async def on_member_join(self, member: discord.Member):
if await self.bot.cog_disabled_in_guild(self, member.guild):
return
await self.update_infochannel_with_cooldown(member.guild) await self.update_infochannel_with_cooldown(member.guild)
@Cog.listener() @Cog.listener()
async def on_member_remove(self, member: discord.Member): async def on_member_remove(self, member: discord.Member):
if await self.bot.cog_disabled_in_guild(self, member.guild):
return
await self.update_infochannel_with_cooldown(member.guild) await self.update_infochannel_with_cooldown(member.guild)
@Cog.listener() @Cog.listener()
async def on_member_update(self, before: discord.Member, after: discord.Member): async def on_member_update(self, before: discord.Member, after: discord.Member):
if await self.bot.cog_disabled_in_guild(self, after.guild):
return
onlinecount = await self.config.guild(after.guild).online_count() onlinecount = await self.config.guild(after.guild).online_count()
if onlinecount: if onlinecount:
if before.status != after.status: if before.status != after.status:

@ -38,6 +38,10 @@ class Leaver(Cog):
@commands.Cog.listener() @commands.Cog.listener()
async def on_member_remove(self, member: discord.Member): async def on_member_remove(self, member: discord.Member):
guild = member.guild guild = member.guild
if await self.bot.cog_disabled_in_guild(self, guild):
return
channel = await self.config.guild(guild).channel() channel = await self.config.guild(guild).channel()
if channel != "": if channel != "":

@ -89,6 +89,8 @@ class LastSeen(Cog):
@commands.Cog.listener() @commands.Cog.listener()
async def on_member_update(self, before: discord.Member, after: discord.Member): async def on_member_update(self, before: discord.Member, after: discord.Member):
if before.status != self.offline_status and after.status == self.offline_status: if before.status != self.offline_status and after.status == self.offline_status:
if not await self.config.guild(before.guild).enabled(): if await self.bot.cog_disabled_in_guild(self, after.guild):
return
if not await self.config.guild(after.guild).enabled():
return return
await self.config.member(before).seen.set(datetime.utcnow().isoformat()) await self.config.member(before).seen.set(datetime.utcnow().isoformat())

@ -96,6 +96,9 @@ class Nudity(commands.Cog):
# print("did not qualify") # print("did not qualify")
return return
if await self.bot.cog_disabled_in_guild(self, message.guild):
return
try: try:
is_on = await self.config.guild(message.guild).enabled() is_on = await self.config.guild(message.guild).enabled()
except AttributeError: except AttributeError:

@ -281,6 +281,9 @@ class ReactRestrict(Cog):
if member.bot: if member.bot:
return return
if await self.bot.cog_disabled_in_guild(self, member.guild):
return
try: try:
roles = [self._get_role(member.guild, c.role_id) for c in combos] roles = [self._get_role(member.guild, c.role_id) for c in combos]
except LookupError: except LookupError:

@ -181,6 +181,10 @@ class StealEmoji(Cog):
# print("Collecting is off") # print("Collecting is off")
return return
guild: discord.Guild = getattr(user, "guild", None)
if await self.bot.cog_disabled_in_guild(self, guild): # Handles None guild just fine
return
emoji: discord.Emoji = reaction.emoji emoji: discord.Emoji = reaction.emoji
if emoji in self.bot.emojis: if emoji in self.bot.emojis:
# print("Emoji already in bot.emojis") # print("Emoji already in bot.emojis")

@ -3,12 +3,13 @@
"Bobloy" "Bobloy"
], ],
"min_bot_version": "3.3.0", "min_bot_version": "3.3.0",
"max_bot_version": "3.3.12",
"description": "Customizable Werewolf Game", "description": "Customizable Werewolf Game",
"hidden": true, "hidden": true,
"install_msg": "Thank you for installing Werewolf! Get started with `[p]load werewolf`\n Use `[p]wwset` to run inital setup", "install_msg": "Thank you for installing Werewolf! Get started with `[p]load werewolf`\n Use `[p]wwset` to run inital setup",
"requirements": [], "requirements": [],
"short": "Werewolf Game", "short": "Werewolf Game",
"end_user_data_statement": "This store user IDs in memory while they're actively using the cog, and store no persistent End User Data.", "end_user_data_statement": "This store user IDs in memory while they're actively using the cog, and stores no persistent End User Data.",
"tags": [ "tags": [
"mafia", "mafia",
"werewolf", "werewolf",

Loading…
Cancel
Save