Skip to content

Commit

Permalink
run black on all files
Browse files Browse the repository at this point in the history
  • Loading branch information
howardt12345 committed Aug 4, 2024
1 parent 2c46f54 commit bc2ecd5
Show file tree
Hide file tree
Showing 57 changed files with 588 additions and 703 deletions.
40 changes: 20 additions & 20 deletions activities/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
# "streaming", # ! not supported yet
}
ACTIVITY_TYPES = list(ACTIVITIES_DICT.keys())
ACTIVITY_CHOICES = [
Choice(name=activity_type, value=activity_type) for activity_type in ACTIVITY_TYPES
]
ACTIVITY_CHOICES = [Choice(name=activity_type, value=activity_type) for activity_type in ACTIVITY_TYPES]


def get_random_activity_type():
return choice(ACTIVITY_TYPES)

def get_activity_item(activity_type: str, index:int = None):

def get_activity_item(activity_type: str, index: int = None):
"""
Returns a random activity item based on the activity type.
If index is provided, returns the item at that index.
Expand All @@ -31,6 +31,7 @@ def get_activity_item(activity_type: str, index:int = None):
elif activity_type == "playing":
return LIST_OF_GAMES[index] if index is not None else choice(LIST_OF_GAMES)


def get_random_activity_as_discordpy_activity():
# get random activity type, then get random item from that activity type, then return it as a discord.Activity object
activity_type = get_random_activity_type()
Expand All @@ -40,9 +41,8 @@ def get_random_activity_as_discordpy_activity():
elif activity_type == "playing":
return discord.Activity(name=activity_name, type=discord.ActivityType.playing)

def register_commands(
tree, this_guild: discord.Object, client: discord.Client
):

def register_commands(tree, this_guild: discord.Object, client: discord.Client):
@tree.command(
name="set_activity",
description=f"Sets the bot's status to an activity type (see: `/list_activities` and `/list_activity_items`).",
Expand All @@ -51,7 +51,9 @@ def register_commands(
@app_commands.checks.has_permissions(administrator=True)
@app_commands.choices(activity_choice=ACTIVITY_CHOICES)
@app_commands.describe(activity_choice="The activity type to set the bot's status to (random if not specified)")
@app_commands.describe(activity_index="The index of the activity item to set the bot's status to (random if not specified)")
@app_commands.describe(
activity_index="The index of the activity item to set the bot's status to (random if not specified)"
)
async def set_activity(
interaction: discord.Interaction, activity_choice: Choice[str] = None, activity_index: int = None
):
Expand All @@ -64,20 +66,18 @@ async def set_activity(
activity_type = get_random_activity_type() if activity_choice is None else activity_choice.value
activity_list_to_use = ACTIVITIES_DICT[activity_type]
if activity_index is not None and activity_index < 0 and activity_index >= len(activity_list_to_use):
await interaction.response.send_message(
"Invalid activity index. Please try again.", ephemeral=True
)
await interaction.response.send_message("Invalid activity index. Please try again.", ephemeral=True)
return
activity_name = activity_list_to_use[activity_index] if activity_index is not None else get_activity_item(activity_type)
await interaction.response.send_message(f"Set bot status to '{activity_type}' with value '{activity_name}' (index: {activity_index})")
activity_name = (
activity_list_to_use[activity_index] if activity_index is not None else get_activity_item(activity_type)
)
await interaction.response.send_message(
f"Set bot status to '{activity_type}' with value '{activity_name}' (index: {activity_index})"
)
if activity_type == "watching":
activity = discord.Activity(
name=activity_name, type=discord.ActivityType.watching
)
activity = discord.Activity(name=activity_name, type=discord.ActivityType.watching)
elif activity_type == "playing":
activity = discord.Activity(
name=activity_name, type=discord.ActivityType.playing
)
activity = discord.Activity(name=activity_name, type=discord.ActivityType.playing)
await client.change_presence(activity=activity)

@tree.command(
Expand Down Expand Up @@ -105,4 +105,4 @@ async def list_activity_items(interaction: discord.Interaction, activity_choice:
activity_list = "\n".join([f"{i}: {activity}" for i, activity in enumerate(ACTIVITIES_DICT[activity_type])])
await interaction.response.send_message(
f"Here are the items for the activity type `{activity_type}`:\n{activity_list}",
)
)
2 changes: 1 addition & 1 deletion activities/playing_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"Detention / 返校",
"Devotion / 還願",
"9 Sols / 九日",
)
)
2 changes: 1 addition & 1 deletion activities/watching.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
# await interaction.response.send_message(
# f"Here are the movies that the bot can watch:\n{movie_list}",
# # ephemeral=True,
# )
# )
4 changes: 1 addition & 3 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ def __init__(self, is_prod: bool, *args, **kwargs) -> None:
# config
self.is_prod = is_prod
self.guilds_dict = fetch_config(is_prod)
super().__init__(
intents=intents, activity=movie_activity, *args, **kwargs
)
super().__init__(intents=intents, activity=movie_activity, *args, **kwargs)

@tasks.loop(hours=CHANGE_STATUS_INTERVAL_HOURS)
async def set_activity(self):
Expand Down
9 changes: 5 additions & 4 deletions commands/basic/basic_commands.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

from discord import app_commands

import discord


def register_commands(
tree: discord.app_commands.CommandTree,
guilds: list[discord.Object],
Expand All @@ -15,14 +15,15 @@ def register_commands(
async def website(interaction: discord.Interaction):
await interaction.response.send_message("https://placetw.com/")


@tree.command(
name="invite",
description="Invite this bot to your server!",
guilds=guilds,
)
async def invite_link(interaction: discord.Interaction):
await interaction.response.send_message("https://discord.com/oauth2/authorize?client_id=1134650883637006407&&permissions=2147484672&scope=bot")
await interaction.response.send_message(
"https://discord.com/oauth2/authorize?client_id=1134650883637006407&&permissions=2147484672&scope=bot"
)

@tree.command(
name="echo",
Expand All @@ -31,4 +32,4 @@ async def invite_link(interaction: discord.Interaction):
)
@app_commands.describe(given_str="The string you want echoed backed")
async def echo(interaction: discord.Interaction, given_str: str):
await interaction.response.send_message(f"You sent this: `{given_str}`")
await interaction.response.send_message(f"You sent this: `{given_str}`")
130 changes: 30 additions & 100 deletions commands/bbt_count/bbt_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,18 @@ def register_commands(
client: TWPlaceClient,
guilds: list[discord.Object],
):
bbt_count = app_commands.Group(
name="bbt_count", description="Bubble tea counts"
)
bbt_count = app_commands.Group(name="bbt_count", description="Bubble tea counts")

# add
@bbt_count.command(name="add", description="Add a new bubble tea entry")
@app_commands.describe(
description="Short description of the bubble tea that you got"
)
@app_commands.describe(
date="Date of the bubble tea (optional, must be in the format YYYY-MM-DD, e.g. 2021-12-31)"
)
@app_commands.describe(
location="Where you got the bubble tea from (optional)"
)
@app_commands.describe(
image="Image of the bubble tea (optional, not saved in database)"
)
@app_commands.describe(description="Short description of the bubble tea that you got")
@app_commands.describe(date="Date of the bubble tea (optional, must be in the format YYYY-MM-DD, e.g. 2021-12-31)")
@app_commands.describe(location="Where you got the bubble tea from (optional)")
@app_commands.describe(image="Image of the bubble tea (optional, not saved in database)")
@app_commands.describe(price="Price of the bubble tea (optional)")
@app_commands.describe(
currency="Currency of the price (optional, Taiwan dollar = TWD, US dollar = USD, etc.)"
)
@app_commands.describe(currency="Currency of the price (optional, Taiwan dollar = TWD, US dollar = USD, etc.)")
@app_commands.describe(notes="Additional notes (optional)")
@app_commands.describe(
rating="Personal rating of the bubble tea (optional)"
)
@app_commands.describe(rating="Personal rating of the bubble tea (optional)")
async def bbt_count_add(
interaction: discord.Interaction,
description: str,
Expand Down Expand Up @@ -114,9 +100,7 @@ async def bbt_count_add(
"generated_id": str(id),
"metadata": add_data,
}
await logging.log_event(
interaction, log_event, content=description, log_to_channel=False
)
await logging.log_event(interaction, log_event, content=description, log_to_channel=False)

embed = bbt_entry_embed(
id,
Expand Down Expand Up @@ -162,16 +146,8 @@ async def bbt_count_get(interaction: discord.Interaction, id: int):
id,
None,
None,
(
interaction.user.display_name
if interaction.user.id == entry.get("user_id")
else None
),
(
interaction.user.avatar.url
if interaction.user.id == entry.get("user_id")
else None
),
(interaction.user.display_name if interaction.user.id == entry.get("user_id") else None),
(interaction.user.avatar.url if interaction.user.id == entry.get("user_id") else None),
entry,
interaction.created_at.astimezone().tzinfo,
)
Expand All @@ -180,27 +156,15 @@ async def bbt_count_get(interaction: discord.Interaction, id: int):
# edit
@bbt_count.command(name="edit", description="Edit a bubble tea entry")
@app_commands.describe(id="ID of the bubble tea entry to edit")
@app_commands.describe(
date="Date of the bubble tea (optional, must be in the format YYYY-MM-DD, e.g. 2021-12-31)"
)
@app_commands.describe(
description="Short description of the bubble tea that you got (optional)"
)
@app_commands.describe(
location="Where you got the bubble tea from (optional)"
)
@app_commands.describe(
image="Image of the bubble tea (optional, not saved in database)"
)
@app_commands.describe(date="Date of the bubble tea (optional, must be in the format YYYY-MM-DD, e.g. 2021-12-31)")
@app_commands.describe(description="Short description of the bubble tea that you got (optional)")
@app_commands.describe(location="Where you got the bubble tea from (optional)")
@app_commands.describe(image="Image of the bubble tea (optional, not saved in database)")
@app_commands.describe(price="Price of the bubble tea (optional)")
@app_commands.describe(currency="Currency of the price (optional)")
@app_commands.describe(notes="Additional notes (optional)")
@app_commands.describe(
rating="Personal rating of the bubble tea (optional)"
)
@app_commands.describe(
transfer_user="Transfer the entry to another user (optional)"
)
@app_commands.describe(rating="Personal rating of the bubble tea (optional)")
@app_commands.describe(transfer_user="Transfer the entry to another user (optional)")
async def bbt_count_edit(
interaction: discord.Interaction,
id: int,
Expand Down Expand Up @@ -295,9 +259,7 @@ def __init__(self):
super().__init__()
self.msg: discord.Message = None

@discord.ui.button(
label="Yes", style=discord.ButtonStyle.green
)
@discord.ui.button(label="Yes", style=discord.ButtonStyle.green)
async def transfer_button_yes(
self,
interaction: discord.Interaction,
Expand All @@ -317,9 +279,7 @@ async def transfer_button_no(
interaction: discord.Interaction,
button: discord.ui.Button,
):
await self.msg.edit(
content="Transfer cancelled", embed=None, view=None
)
await self.msg.edit(content="Transfer cancelled", embed=None, view=None)
# Cancel the transfer and edit the entry normally
await edit()

Expand All @@ -339,12 +299,8 @@ async def transfer_button_no(
name="list",
description="List the bubble tea entries for a user in a given year",
)
@app_commands.describe(
user="User to list entries for (optional, default to self)"
)
@app_commands.describe(
year="Year to list entries for (optional, default to current year)"
)
@app_commands.describe(user="User to list entries for (optional, default to self)")
@app_commands.describe(year="Year to list entries for (optional, default to current year)")
@app_commands.describe(group_by="Field to group by (optional)")
@app_commands.choices(group_by=BBT_LIST_GROUP_BY_CHOICES)
async def bbt_count_list(
Expand All @@ -354,9 +310,7 @@ async def bbt_count_list(
group_by: app_commands.Choice[str] = None,
):
await interaction.response.defer()
entries = get_bbt_entries(
user.id if user else interaction.user.id, year
)
entries = get_bbt_entries(user.id if user else interaction.user.id, year)
embed = (
bbt_list_default_embed(
user.id if user else interaction.user.id,
Expand All @@ -380,20 +334,12 @@ async def bbt_count_list(
name="leaderboard",
description="List the top bubble tea drinkers in a given year",
)
@app_commands.describe(
year="Year to list leaderboard for (optional, default to current year)"
)
async def bbt_count_leaderboard(
interaction: discord.Interaction, year: int = None
):
@app_commands.describe(year="Year to list leaderboard for (optional, default to current year)")
async def bbt_count_leaderboard(interaction: discord.Interaction, year: int = None):
await interaction.response.defer()
leaderboard = get_bbt_leaderboard(
interaction.guild.id,
(
datetime.datetime(year=year, month=1, day=1)
if year
else interaction.created_at
),
(datetime.datetime(year=year, month=1, day=1) if year else interaction.created_at),
)
embed = discord.Embed(
title=f"Top bubble tea drinkers of {year if year else interaction.created_at.year} in {client.guilds_dict[interaction.guild.id]['server_name']}",
Expand All @@ -412,18 +358,10 @@ async def bbt_count_leaderboard(
)
await interaction.followup.send(embed=embed)

@bbt_count.command(
name="stats", description="Get the stats for a user for a given year"
)
@app_commands.describe(
user="User to get stats for (optional, default to self)"
)
@app_commands.describe(
year="Year to get stats for (optional, default to current year)"
)
@app_commands.describe(
group_by_location="Group the stats by location (optional)"
)
@bbt_count.command(name="stats", description="Get the stats for a user for a given year")
@app_commands.describe(user="User to get stats for (optional, default to self)")
@app_commands.describe(year="Year to get stats for (optional, default to current year)")
@app_commands.describe(group_by_location="Group the stats by location (optional)")
async def bbt_count_stats(
interaction: discord.Interaction,
user: discord.User = None,
Expand All @@ -434,20 +372,12 @@ async def bbt_count_stats(
user_id = user.id if user else interaction.user.id
stats = get_bubble_tea_stats(
user_id,
(
datetime.datetime(year=year, month=1, day=1)
if year
else interaction.created_at
),
(datetime.datetime(year=year, month=1, day=1) if year else interaction.created_at),
group_by_location,
)
monthly_counts = get_bubble_tea_monthly_counts(
user_id,
(
datetime.datetime(year=year, month=1, day=1)
if year
else interaction.created_at
),
(datetime.datetime(year=year, month=1, day=1) if year else interaction.created_at),
)

latest = (
Expand Down
4 changes: 1 addition & 3 deletions commands/bbt_count/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
"currency": "Currency",
}

BBT_LIST_GROUP_BY_CHOICES = [
Choice(name=desc, value=field) for field, desc in BBT_LIST_GROUP_BY.items()
]
BBT_LIST_GROUP_BY_CHOICES = [Choice(name=desc, value=field) for field, desc in BBT_LIST_GROUP_BY.items()]
4 changes: 1 addition & 3 deletions commands/bbt_count/db_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ def get_bbt_leaderboard(guild_id: int, date: datetime):


# Gets the bubble tea stats for a user in a given year
def get_bubble_tea_stats(
user_id: int, date: datetime, group_by_location=False
):
def get_bubble_tea_stats(user_id: int, date: datetime, group_by_location=False):
data, c = supabaseClient.rpc(
"get_bubble_tea_stats",
{
Expand Down
Loading

0 comments on commit bc2ecd5

Please sign in to comment.