Skip to content

Commit

Permalink
FIxes for cog errors pointed in app review (#45)
Browse files Browse the repository at this point in the history
* update author variable

* replace fuzzywuzzy with rapidfuzz

* hit or miss error fixes

* joinping error fixes

* notes error fixes

* lots of different error fixes

* Style Reformatting

---------

Co-authored-by: {{ github.actor }} <i-am-zaidali@users.noreply.github.com>
  • Loading branch information
i-am-zaidali and i-am-zaidali committed Jun 20, 2023
1 parent 9aefcb5 commit 2803d2f
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 103 deletions.
4 changes: 2 additions & 2 deletions hitormiss/converters.py
@@ -1,5 +1,5 @@
from discord.ext.commands.converter import UserConverter
from fuzzywuzzy.process import extractOne
from rapidfuzz.process import extractOne
from redbot.core.commands import Converter

from .CONSTANTS import user_defaults
Expand All @@ -10,7 +10,7 @@
class ItemConverter(Converter):
async def convert(self, ctx, name: str):
items = ctx.cog.items
match = extractOne(name, items.keys(), score_cutoff=80)
match = extractOne(name.lower(), items.keys(), score_cutoff=70)
if match:
return items[match[0]]

Expand Down
8 changes: 5 additions & 3 deletions hitormiss/info.json
@@ -1,4 +1,3 @@

{
"name": "HitOrMiss",
"short": "Throw items at other users bought from the shop through the bot's currency.",
Expand All @@ -9,7 +8,10 @@
"crayyy_zee"
],
"required_cogs": {},
"requirements": ["emoji==1.6.3"],
"requirements": [
"emoji",
"rapidfuzz"
],
"tags": [
"snow",
"christmas",
Expand All @@ -18,4 +20,4 @@
"shop"
],
"type": "COG"
}
}
69 changes: 46 additions & 23 deletions hitormiss/main.py
Expand Up @@ -7,22 +7,20 @@

import discord
from discord.ext.commands.converter import EmojiConverter
from emoji.unicode_codes import UNICODE_EMOJI_ENGLISH
from emoji import EMOJI_DATA
from redbot.core import Config, bank, commands
from redbot.core.bot import Red
from redbot.core.errors import CogLoadError
from redbot.core.utils.chat_formatting import box, humanize_list, pagify
from redbot.core.utils.menus import DEFAULT_CONTROLS, menu
from redbot.core.utils.predicates import MessagePredicate
from tabulate import tabulate

from hitormiss.views import PaginationView

from .CONSTANTS import dc_fields, global_defaults, lb_types, user_defaults
from .converters import ItemConverter, PlayerConverter
from .exceptions import ItemOnCooldown
from .models import BaseItem, Player
from .utils import is_lt, no_special_characters
from .views import PaginationView

log = logging.getLogger("red.craycogs.HitOrMiss")

Expand All @@ -34,7 +32,7 @@ class HitOrMiss(commands.Cog):
And no it doesn't use slash commands.
*Yet*."""

__author__ = ["crayyy_zee#2900"]
__author__ = ["crayyy_zee"]
__version__ = "1.3.5"

def __init__(self, bot: Red):
Expand Down Expand Up @@ -149,7 +147,7 @@ async def ask_for_answers(
if m.content.lower() == "none":
emoji = None

elif m.content not in UNICODE_EMOJI_ENGLISH.keys():
elif not EMOJI_DATA.get(m.content):
try:
emoji = await EmojiConverter().convert(ctx, m.content)
except Exception as e:
Expand Down Expand Up @@ -217,15 +215,16 @@ async def cog_unload(self):

@commands.command(name="throw")
@commands.cooldown(1, 5, commands.BucketType.user)
async def throw(self, ctx, item: str = None, target: PlayerConverter = None):
"""Throw an item you own at a user"""
if not item or not target:
return await ctx.send_help()
async def throw(
self,
ctx,
item: BaseItem = commands.parameter(converter=ItemConverter),
target: Player = commands.parameter(converter=PlayerConverter),
):
"""Throw an item you own at a user
try:
item: BaseItem = await ItemConverter().convert(ctx, item)
except Exception as e:
return await ctx.send(str(e))
`item` is the name of the item you want to throw
`target` is the user you want to throw the item at"""

if not item.throwable:
return await ctx.send(f"No, a {item} can not be thrown at others.")
Expand Down Expand Up @@ -277,6 +276,7 @@ async def hom(self, ctx):
await ctx.send_help(ctx.command)

@hom.command(name="shop", aliases=["items"])
@commands.bot_has_permissions(embed_links=True)
async def hom_shop(self, ctx: commands.Context):
"""
See items available to buy for Hit Or Miss.
Expand Down Expand Up @@ -305,13 +305,14 @@ async def hom_shop(self, ctx: commands.Context):
title="Hit or Miss Shop",
description="All the items available in H.O.M",
color=(await ctx.embed_color()).value,
thumbnail=getattr(ctx.guild.icon, "url", None),
thumbnail__url=getattr(ctx.guild.icon, "url", None),
)

view = PaginationView(ctx, embeds, 60, True)
await view.start()

@hom.command(name="inventory", aliases=["inv"])
@commands.bot_has_permissions(embed_links=True)
async def hom_inv(self, ctx: commands.Context):
"""
See all the items that you currently own in Hit Or Miss."""
Expand Down Expand Up @@ -357,12 +358,19 @@ async def hom_inv(self, ctx: commands.Context):

@hom.command(name="buy", aliases=["purchase"], usage="[amount] <item>")
async def hom_buy(
self, ctx: commands.Context, amount: Optional[int] = None, item: ItemConverter = None
self,
ctx: commands.Context,
amount: Optional[int] = None,
item: BaseItem = commands.parameter(converter=ItemConverter),
):
"""
Buy a Hit Or Miss item for your inventory."""
if not item:
return await ctx.send_help()
Buy a Hit Or Miss item for your inventory.
`[p]buy <item>` to buy 1 of the item.
`[p]buy <amount> <item>` to buy a specific amount of the item.
where,
`<item>` is the name of the item you want to buy."""
amount = amount or 1
needed_to_buy = int(item.price) * amount
if await bank.can_spend(ctx.author, needed_to_buy):
Expand All @@ -379,7 +387,12 @@ async def hom_buy(
)

@hom.command(name="stats", aliases=["profile"])
async def hom_stats(self, ctx: commands.Context, user: PlayerConverter = None):
@commands.bot_has_permissions(embed_links=True)
async def hom_stats(
self,
ctx: commands.Context,
user: Player = commands.parameter(converter=PlayerConverter, default=None),
):
"""
See yours or others Hit Or Miss stats."""
user: Player = user or await self.converter.convert(ctx, str(ctx.author.id))
Expand All @@ -392,6 +405,7 @@ async def hom_stats(self, ctx: commands.Context, user: PlayerConverter = None):
await ctx.send(embed=embed)

@hom.command(name="createitem", aliases=["make", "create", "newitem", "ci"])
@commands.bot_has_permissions(embed_links=True)
@commands.is_owner()
async def hom_create(self, ctx: commands.Context):
"""
Expand Down Expand Up @@ -453,7 +467,7 @@ async def hom_create(self, ctx: commands.Context):

name = answers.pop("name")

if functools.reduce(lambda x: x.lower() == name.lower(), self.items.keys()):
if next(filter(lambda x: x.lower() == name.lower(), self.items.keys()), None) is None:
return await ctx.send(f"An item with the name `{name}` already exists.")

answers["throwable"] = True
Expand All @@ -470,7 +484,9 @@ async def hom_create(self, ctx: commands.Context):

@hom.command(name="deleteitem", aliases=["remove", "delete", "di"])
@commands.is_owner()
async def hom_delete(self, ctx: commands.Context, item: ItemConverter):
async def hom_delete(
self, ctx: commands.Context, item: BaseItem = commands.parameter(converter=ItemConverter)
):
"""
Delete an item from the Hit Or Miss shop that you created.
Expand All @@ -490,8 +506,12 @@ async def hom_delete(self, ctx: commands.Context, item: ItemConverter):
cooldown_after_parsing=True,
usage="[type=kills] [global_or_local=False]",
)
@commands.bot_has_permissions(embed_links=True)
async def hom_lb(
self, ctx: commands.Context, _type: str = "kills", global_or_local: bool = False
self,
ctx: commands.Context,
_type: Literal["kills", "throws", "deaths", "hits", "misses", "kdr", "all"] = "kills",
global_or_local: Union[Literal["global", "local"], bool] = False,
):
"""
Show the top players in the Hit Or Miss leaderboard.
Expand All @@ -517,6 +537,9 @@ async def hom_lb(

final = []

if isinstance(global_or_local, str):
global_or_local = True if global_or_local == "global" else False

users = self.cache.copy()
if not users:
return await ctx.send(
Expand Down
9 changes: 8 additions & 1 deletion joinping/main.py
Expand Up @@ -20,7 +20,7 @@ class JoinPing(commands.Cog):
Ghost ping users when they join."""

__version__ = "1.1.0"
__author__ = ["crayyy_zee#2900"]
__author__ = ["crayyy_zee"]

def __init__(self, bot: Red):
self.bot = bot
Expand Down Expand Up @@ -99,6 +99,7 @@ async def jpset(self, ctx):
return await ctx.send_help()

@jpset.command(name="test", aliases=["testping"], hidden=True)
@commands.bot_has_permissions(embed_links=True)
async def jpset_test(self, ctx):
"""
Test whether the pings and message you set up work correctly.
Expand All @@ -111,6 +112,7 @@ async def jpset_test(self, ctx):
await self.on_member_join(ctx.author)

@jpset.command(name="deleteafter", aliases=["da"])
@commands.bot_has_permissions(embed_links=True)
async def jpset_da(self, ctx, seconds: int):
"""Set the time in seconds after which the ping message will be deleted."""
if seconds < 0:
Expand All @@ -120,6 +122,7 @@ async def jpset_da(self, ctx, seconds: int):
await ctx.send(f"The ping message will be deleted after {seconds} seconds.")

@jpset.command(name="message", aliases=["m"])
@commands.bot_has_permissions(embed_links=True)
async def jpset_msg(self, ctx, *, message: str):
"""Set the message that will be sent when a user joins.
Expand All @@ -139,12 +142,14 @@ async def jpset_msg(self, ctx, *, message: str):
await ctx.send(f"The ping message has been set to:\n{message}")

@jpset.group(name="channel", aliases=["c", "channels"], invoke_without_command=True)
@commands.bot_has_permissions(embed_links=True)
async def jpset_channels(self, ctx):
"""
Set the channels where the pings will be sent on member join."""
return await ctx.send_help()

@jpset_channels.command(name="remove", aliases=["r"])
@commands.bot_has_permissions(embed_links=True)
async def jpsetchan_remove(self, ctx, *channels: discord.TextChannel):
"""
Add the channels to the list of channels where the pings will be sent on member join."""
Expand All @@ -170,6 +175,7 @@ async def jpsetchan_remove(self, ctx, *channels: discord.TextChannel):
)

@jpset_channels.command(name="add", aliases=["a"])
@commands.bot_has_permissions(embed_links=True)
async def jpsetchan_add(self, ctx, *channels: discord.TextChannel):
"""
Remove the channels from the list of channels where the pings will be sent on member join.
Expand All @@ -190,6 +196,7 @@ async def jpsetchan_add(self, ctx, *channels: discord.TextChannel):
)

@jpset.command(name="show", aliases=["showsettings", "settings", "setting"])
@commands.bot_has_permissions(embed_links=True)
async def jpset_show(self, ctx):
"""
Show the current joinping settings.
Expand Down
4 changes: 3 additions & 1 deletion keywordpoints/main.py
Expand Up @@ -34,7 +34,7 @@ class KeyWordPoints(commands.Cog):
"""

__version__ = "1.0.8"
__author__ = ["crayyy_zee#2900"]
__author__ = ["crayyy_zee"]

def __init__(self, bot: Red):
self.bot = bot
Expand Down Expand Up @@ -244,6 +244,7 @@ async def kwp_remove(self, ctx: commands.Context, keyword: str):
await ctx.send(cf.success(f"Keyword `{keyword}` removed."))

@kwp.command(name="list")
@commands.bot_has_permissions(embed_links=True)
@commands.mod_or_permissions(manage_guild=True)
async def kwp_list(self, ctx: commands.Context):
"""List all keywords in this server."""
Expand Down Expand Up @@ -282,6 +283,7 @@ def handle_keyword(keyword: str):
await menu(ctx, embeds, DEFAULT_CONTROLS)

@kwp.command(name="leaderboard", aliases=["lb"])
@commands.bot_has_permissions(embed_links=True)
async def kwp_lb(self, ctx: commands.Context):
"""
See a leaderboard of points of each member in the server."""
Expand Down

0 comments on commit 2803d2f

Please sign in to comment.