Skip to content

Commit

Permalink
Red 3.1 support with 3.0.2 backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
TrustyJAID committed May 6, 2019
1 parent fc14467 commit 11f6d76
Show file tree
Hide file tree
Showing 31 changed files with 370 additions and 85 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -15,7 +15,7 @@ To add the cogs to your instance please do: `[p]repo add Trusty-cogs https://git
| --- | --- | --- |
| Hockey | **2.4.0** | <details><summary>A cog to gather hockey scores, schedules, player data and more!</summary> If you would like to use the built in emoljis, ask me (TrustyJAID#0001) on discord to add your bot to my server hosting the emojis used in this cog. There is also a command to set your own custom emojis.</details>|
| Notsobot | **Release**| <details><summary>Working cog for many of NotSoBot's commands.</summary> Has lots of requirements, view the [cog README.md](https://github.com/TrustyJAID/Trusty-cogs/blob/master/notsobot/README.md) for details. </details> |
| ReTrigger | **2.4.5** | <details><summary>Trigger events based on regex!</summary>Note: This repo requires pillow to allow resizing of images.</details> |
| ReTrigger | **2.6.5** | <details><summary>Trigger events based on regex!</summary>Note: This repo requires pillow to allow resizing of images.</details> |
| Spoiler | **Beta**| <details><summary>Post spoiler messages in chat and react to the message to view the spoilers. </summary></details> |
| ExtendedModLog | **2.1.0**| <details><summary>An in depth extension of RedBot's built in modlog. </summary>Handles message edits, message deletes, mod bot commands, channel updates, server updates, emoji changes and more </details> |
| Badges | **Release** | <details><summary>Create your own badge with your discord info.</summary> Includes templates for fake CIA, NSA, FBI, Discord, and every NHL hockey team. Requirements: pillow</details> |
Expand Down Expand Up @@ -55,7 +55,7 @@ To add the cogs to your instance please do: `[p]repo add Trusty-cogs https://git
| Chatter | **Alpha** | <details><summary>Currently disabled until I can work on it.</summary>Teach your bot how to talk by watching conversations on servers and reply. Uses chatterbot library. NOTE: This cog is not recommended to be used at this time. After a month of usage it caused the whole bot to slow down while it searched for responses. I recommend looking at cleverbot for the time being.</details> |


## Rewritten Cogs Originally Made by others
## Rewritten Cogs Originally Made by others
*These cogs were originally written by others for V2. As they were used frequently on TrustyBot I ported them over quickly for V3. A better version may be available.*

| Name | Status | Description (Click to see full status)
Expand Down
10 changes: 9 additions & 1 deletion addimage/addimage.py
Expand Up @@ -11,6 +11,11 @@


_ = Translator("AddImage", __file__)
listener = getattr(commands.Cog, "listener", None) # red 3.0 backwards compatibility support

if listener is None: # thanks Sinbad
def listener(name=None):
return lambda x: x


@cog_i18n(_)
Expand Down Expand Up @@ -138,6 +143,7 @@ async def check_ignored_channel(self, message):
chann_ignored = await mod.settings.channel(channel).ignored()
return not (guild_ignored or chann_ignored and not perms.manage_channels)

@listener()
async def on_message(self, message):
if len(message.content) < 2 or message.guild is None:
return
Expand Down Expand Up @@ -424,5 +430,7 @@ async def add_image_global(self, ctx, name: str):
else:
await self.save_image_location(ctx.message, name)

def __unload(self):
def cog_unload(self):
self.bot.loop.create_task(self.session.close())

__unload = cog_unload
6 changes: 6 additions & 0 deletions apngfilter/apngfilter.py
Expand Up @@ -6,6 +6,11 @@

IS_LINK_REGEX = re.compile(r"(http(s?):)([/|.|\w|\s|-])*\.(?:png)")
APNG_REGEX = re.compile(rb"fdAT") # credit to Soulrift for researh on this
listener = getattr(commands.Cog, "listener", None) # red 3.0 backwards compatibility support

if listener is None: # thanks Sinbad
def listener(name=None):
return lambda x: x


class APNGFilter(commands.Cog):
Expand All @@ -32,6 +37,7 @@ async def apngfilter(self, ctx):
msg = "Enabled"
await ctx.send("APNG Filter " + msg)

@listener()
async def on_message(self, message):
if not message.guild:
return
Expand Down
23 changes: 15 additions & 8 deletions autorole/autorole.py
Expand Up @@ -13,12 +13,17 @@
"AGREE_KEY": None,
}
_ = Translator("Autorole", __file__)
listener = getattr(commands.Cog, "listener", None) # red 3.0 backwards compatibility support

if listener is None: # thanks Sinbad
def listener(name=None):
return lambda x: x


@cog_i18n(_)
class Autorole(commands.Cog):
"""
Autorole commands. Rewritten for V3 from
Autorole commands. Rewritten for V3 from
https://github.com/Lunar-Dust/Dusty-Cogs/blob/master/autorole/autorole.py
"""

Expand Down Expand Up @@ -52,6 +57,7 @@ async def get_colour(self, guild):
else:
return await self.bot.db.color()

@listener()
async def on_message(self, message):
guild = message.guild
user = message.author
Expand Down Expand Up @@ -126,6 +132,7 @@ async def _auto_give(self, member):
for role in roles:
await member.add_roles(role, reason=_("Joined the server"))

@listerner()
async def on_member_join(self, member):
guild = member.guild
if await self.config.guild(guild).ENABLED():
Expand Down Expand Up @@ -209,7 +216,7 @@ async def toggle(self, ctx):
async def role(self, ctx, *, role: discord.Role):
"""
Add a role for autorole to assign.
You can use this command multiple times to add multiple roles.
"""
guild = ctx.message.guild
Expand Down Expand Up @@ -251,19 +258,19 @@ async def remove(self, ctx, *, role: discord.Role):
async def agreement(self, ctx):
"""
Set the channel and message that will be used for accepting the rules.
`channel` is the channel they must type the key in to get the role.
`key` is the message they must type to gain access and must be in quotes.
`msg` is the message DM'd to them when they join.
`{key}` must be included in the message so a user knows what to type in the channel.
Optional additions to the message include:
`{channel}` Mentions the channel where they must include the agreement message.
`{mention}` Mentions the user incase they have DM permissions turned off this should be used.
`{name}` Says the member name if you don't want to ping them.
`{guild}` Says the servers current name.
Entering nothing will disable these.
"""
pass
Expand Down Expand Up @@ -351,19 +358,19 @@ async def agreement_setup(
):
"""
Set the channel and message that will be used for accepting the rules.
`channel` is the channel they must type the key in to get the role.
`key` is the message they must type to gain access and must be in quotes.
`msg` is the message DM'd to them when they join.
`{key}` must be included in the message so a user knows what to type in the channel.
Optional additions to the message include:
`{channel}` Mentions the channel where they must include the agreement message.
`{mention}` Mentions the user incase they have DM permissions turned off this should be used.
`{name}` Says the member name if you don't want to ping them.
`{guild}` Says the servers current name.
Entering nothing will disable this.
"""
guild = ctx.message.guild
Expand Down
10 changes: 9 additions & 1 deletion cleverbot/cleverbot.py
Expand Up @@ -9,6 +9,11 @@
IO_API_URL = "https://cleverbot.io/1.0"

log = logging.getLogger("red.trusty-cogs.Cleverbot")
listener = getattr(commands.Cog, "listener", None) # red 3.0 backwards compatibility support

if listener is None: # thanks Sinbad
def listener(name=None):
return lambda x: x


class CleverbotError(Exception):
Expand Down Expand Up @@ -233,6 +238,7 @@ async def get_io_credentials(self):
else:
return io_user, io_key

@listener()
async def on_message(self, message):
guild = message.guild
if guild is None:
Expand Down Expand Up @@ -313,5 +319,7 @@ async def on_message(self, message):
else:
await channel.send(response)

def __unload(self):
def cog_unload(self):
self.bot.loop.create_task(self.session.close())

__unload = cog_unload
8 changes: 3 additions & 5 deletions conversions/conversions.py
Expand Up @@ -2,8 +2,6 @@
from redbot.core import commands
import datetime
import aiohttp
import asyncio
import json
import re
from typing import Optional

Expand Down Expand Up @@ -141,7 +139,7 @@ async def multicoin(self, ctx, *, coins=None):
for coin in data["data"]:
coin_list.append(data["data"][coin])
else:
coins = re.split("\W+", coins)
coins = re.split(r"\W+", coins)
for coin in coins:
coin_list.append(await self.checkcoins(coin))
embed = discord.Embed(title="Crypto coin comparison")
Expand All @@ -168,7 +166,7 @@ async def crypto(
):
"""
Displays the latest information about a specified crypto currency
`coin` must be the name or symbol of a crypto coin
`[ammount]` is any number to convert the value of defaults to 1 coin
`[currency]` is the desired currency you want to convert defaults to USD
Expand Down Expand Up @@ -228,7 +226,7 @@ async def crypto_embed(self, ctx, coin, ammount=1.0, currency="USD", full=True):
available_supply = "{0:,.2f}".format(coin_data["circulating_supply"])
try:
max_supply = "{0:,.2f}".format(coin_data["max_supply"])
except:
except KeyError:
max_supply = "\N{INFINITY}"
total_supply = "{0:,.2f}".format(coin_data["total_supply"])
embed.set_thumbnail(url=coin_image)
Expand Down
18 changes: 11 additions & 7 deletions destiny/api.py
Expand Up @@ -7,6 +7,7 @@


from redbot.core.json_io import JsonIO
from redbot.core import Red
from redbot.core import commands, Config, checks
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.data_manager import cog_data_path
Expand Down Expand Up @@ -127,13 +128,16 @@ async def get_o_auth(self, ctx):
"this application and provide "
"everything after `?code=` shown in the URL.\n"
)
check = lambda m: m.author == ctx.message.author
try:
await ctx.author.send(msg + url)
except:
except discord.errors.Forbidden:
await ctx.send(msg + url)
try:
msg = await ctx.bot.wait_for("message", check=check, timeout=60)
msg = await ctx.bot.wait_for(
"message",
check=lambda m: m.author == ctx.message.author,
timeout=60
)
except asyncio.TimeoutError:
return
if msg.content != "exit":
Expand Down Expand Up @@ -181,15 +185,15 @@ async def check_expired_token(self, user: discord.User):
if "refresh_expires_at" not in user_oauth:
try:
refresh = await self.get_refresh_token(user)
except Destiny2InvalidParameters as e:
except Destiny2InvalidParameters:
raise Destiny2RefreshTokenError
refresh["refresh_expires_at"] = now + refresh["refresh_expires_in"]
await self.config.user(user).oauth.set(refresh)
return
if "expires_at" not in user_oauth:
try:
refresh = await self.get_refresh_token(user)
except Destiny2InvalidParameters as e:
except Destiny2InvalidParameters:
raise Destiny2RefreshTokenError
refresh["expires_at"] = now + refresh["expires_in"]
await self.config.user(user).oauth.set(refresh)
Expand All @@ -202,7 +206,7 @@ async def check_expired_token(self, user: discord.User):
if user_oauth["expires_at"] < now:
try:
refresh = await self.get_refresh_token(user)
except Destiny2InvalidParameters as e:
except Destiny2InvalidParameters:
raise Destiny2RefreshTokenError
refresh["expires_at"] = now + refresh["expires_in"]
refresh["refresh_expires_at"] = now + refresh["refresh_expires_in"]
Expand Down Expand Up @@ -382,7 +386,7 @@ async def has_oauth(self, ctx: commands.Context, user: discord.Member = None):
except:
await ctx.send(str(e))
return False
except Destiny2MissingAPITokens as e:
except Destiny2MissingAPITokens:
# await ctx.send(str(e))
return True # Some magic so we can still keep it all under one top level command
data["expires_at"] = now + data["expires_in"]
Expand Down

0 comments on commit 11f6d76

Please sign in to comment.