-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
108 changed files
with
40,703 additions
and
2,620 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
from random import choice | ||
import discord | ||
from discord.app_commands import Choice | ||
from discord import app_commands | ||
from .watching_consts import LIST_OF_MOVIES | ||
from .playing_consts import LIST_OF_GAMES | ||
|
||
ACTIVITIES_DICT = { | ||
"watching": LIST_OF_MOVIES, | ||
"playing": LIST_OF_GAMES, | ||
# "listening", # ! not supported yet | ||
# "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] | ||
|
||
|
||
def get_random_activity_type(): | ||
return choice(ACTIVITY_TYPES) | ||
|
||
|
||
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. | ||
Otherwise, returns a random item. | ||
""" | ||
assert activity_type in ACTIVITY_TYPES, f"Invalid activity type: {activity_type}. Allowed types: {ACTIVITY_TYPES}" | ||
if activity_type == "watching": | ||
return LIST_OF_MOVIES[index] if index is not None else choice(LIST_OF_MOVIES) | ||
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() | ||
activity_name = get_activity_item(activity_type) | ||
if activity_type == "watching": | ||
return discord.Activity(name=activity_name, type=discord.ActivityType.watching) | ||
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): | ||
@tree.command( | ||
name="set_activity", | ||
description=f"Sets the bot's status to an activity type (see: `/list_activities` and `/list_activity_items`).", | ||
guild=this_guild, | ||
) | ||
@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)" | ||
) | ||
async def set_activity( | ||
interaction: discord.Interaction, activity_choice: Choice[str] = None, activity_index: int = None | ||
): | ||
# if activity_index is provided but activity_choice is not, then it's an error | ||
if activity_index is not None and activity_choice is None: | ||
await interaction.response.send_message( | ||
"You must provide the activity type if you want to set the activity index.", ephemeral=True | ||
) | ||
return | ||
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) | ||
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})" | ||
) | ||
if activity_type == "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) | ||
await client.change_presence(activity=activity) | ||
|
||
@tree.command( | ||
name="list_activities", | ||
description="Lists all the activities that the bot can do.", | ||
guild=this_guild, | ||
) | ||
@app_commands.checks.has_permissions(administrator=True) | ||
async def list_activities(interaction: discord.Interaction): | ||
activity_list = "\n".join([f"* {activity_type}" for activity_type in ACTIVITY_TYPES]) | ||
await interaction.response.send_message( | ||
f"Here are the activities that the bot can do:\n{activity_list}", | ||
) | ||
|
||
@tree.command( | ||
name="list_activity_items", | ||
description="Lists all the items for a specific activity.", | ||
guild=this_guild, | ||
) | ||
@app_commands.checks.has_permissions(administrator=True) | ||
@app_commands.choices(activity_choice=ACTIVITY_CHOICES) | ||
@app_commands.describe(activity_choice="The activity type to list the items for") | ||
async def list_activity_items(interaction: discord.Interaction, activity_choice: Choice[str]): | ||
activity_type = activity_choice.value | ||
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}", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
LIST_OF_GAMES = ( | ||
"Detention / 返校", | ||
"Devotion / 還願", | ||
"9 Sols / 九日", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# from random import choice | ||
# import discord | ||
# from discord.app_commands import Choice | ||
# from discord import app_commands | ||
# from .watching_consts import LIST_OF_MOVIES | ||
|
||
# def get_random_movie(): | ||
# return choice(LIST_OF_MOVIES) | ||
|
||
# def register_commands( | ||
# tree, this_guild: discord.Object, client: discord.Client | ||
# ): | ||
# @tree.command( | ||
# name="set_watching", | ||
# description=f"Sets the bot's status to 'Watching' (movie) using a movie's index (/{LIST_MOVIES_CMD_NAME}).", | ||
# guild=this_guild, | ||
# ) | ||
# @app_commands.checks.has_permissions(administrator=True) | ||
# async def set_watching_status( | ||
# interaction: discord.Interaction, movie_index: int | ||
# ): | ||
# if movie_index < 0 or movie_index >= len(LIST_OF_MOVIES): | ||
# await interaction.response.send_message( | ||
# "Invalid movie index. Please try again.", ephemeral=True | ||
# ) | ||
# return | ||
# movie_name = LIST_OF_MOVIES[movie_index] | ||
# movie_activity = discord.Activity( | ||
# name=movie_name, type=discord.ActivityType.watching | ||
# ) | ||
# await client.change_presence(activity=movie_activity) | ||
# await interaction.response.send_message( | ||
# f"Set bot status to 'Watching: {movie_name}'", ephemeral=True | ||
# ) | ||
|
||
# @tree.command( | ||
# name="list_movies", | ||
# description="Lists all the movies that the bot can watch.", | ||
# guild=this_guild, | ||
# ) | ||
# @app_commands.checks.has_permissions(administrator=True) | ||
# async def list_movies(interaction: discord.Interaction): | ||
# movie_list = "\n".join([f"{i}: {movie}" for i, movie in enumerate(LIST_OF_MOVIES)]) | ||
# await interaction.response.send_message( | ||
# f"Here are the movies that the bot can watch:\n{movie_list}", | ||
# # ephemeral=True, | ||
# ) |
81 changes: 49 additions & 32 deletions
81
presence/watching_consts.py → activities/watching_consts.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,49 @@ | ||
from discord.app_commands import Choice | ||
|
||
|
||
LIST_OF_MOVIES = ( | ||
"City of Sadness / 悲情城市", | ||
"7 Days in Heaven / 父後七日", | ||
"Detention / 返校", | ||
"Cape No. 7 / 海角七號", | ||
"The World Between Us / 我們與惡的距離", | ||
"Spicy Teacher / 麻辣鮮師", | ||
"Warriors Of The Rainbow / 賽德克·巴萊", | ||
"The Teenage Psychic / 通靈少女", | ||
"KANO (2014)", | ||
"Incantation / 咒", | ||
"You Are the Apple of My Eye / 那些年,我們一起追的女孩", | ||
"Din Tao: Leader of the Parade / 陣頭", | ||
"Light the Night / 華燈初上", | ||
"Gold Leaf / 茶金", | ||
"Alifu / 阿里夫/芙", | ||
"Your Name Engraved Herein / 刻在我心底的名字", | ||
"Our Times / 我的少女時代", | ||
"The Dull-Ice Flower / 魯冰花", | ||
"Zone Pro Site / 總舖師", | ||
"Beyond Beauty: Taiwan from Above / 看見台灣", | ||
"Monga / 艋舺", | ||
"The Tag-Along / 紅衣小女孩", | ||
"Till We Meet Again / 月老", | ||
) | ||
|
||
MOVIE_CHOICES = [ | ||
Choice(name=movie_name, value=movie_name) for movie_name in LIST_OF_MOVIES | ||
] | ||
from discord.app_commands import Choice | ||
|
||
LIST_MOVIES_CMD_NAME = "list_movies" | ||
|
||
LIST_OF_MOVIES = ( | ||
"City of Sadness / 悲情城市", | ||
"7 Days in Heaven / 父後七日", | ||
"Detention / 返校", | ||
"Cape No. 7 / 海角七號", | ||
"The World Between Us / 我們與惡的距離", | ||
"Spicy Teacher / 麻辣鮮師", | ||
"Warriors Of The Rainbow / 賽德克·巴萊", | ||
"The Teenage Psychic / 通靈少女", | ||
"KANO (2014)", | ||
"Incantation / 咒", | ||
"You Are the Apple of My Eye / 那些年,我們一起追的女孩", | ||
"Din Tao: Leader of the Parade / 陣頭", | ||
"Light the Night / 華燈初上", | ||
"Gold Leaf / 茶金", | ||
"Alifu / 阿里夫/芙", | ||
"Your Name Engraved Herein / 刻在我心底的名字", | ||
"Our Times / 我的少女時代", | ||
"The Dull-Ice Flower / 魯冰花", | ||
"Zone Pro Site / 總舖師", | ||
"Beyond Beauty: Taiwan from Above / 看見台灣", | ||
"Monga / 艋舺", | ||
"The Tag-Along / 紅衣小女孩", | ||
"Till We Meet Again / 月老", | ||
"Little Big Women / 孤味", | ||
"Dear Tenant / 親愛的房客", | ||
"Marry My Dead Body / 關於我和鬼變成家人的那件事", | ||
"My Missing Valentine / 消失的情人節", | ||
"Days / 日子", | ||
"Classmates Minus / 同學麥娜絲", | ||
"The Silent Forest / 無聲", | ||
"I WeirDO / 怪胎", | ||
"The Falls / 瀑布", | ||
"Man in Love / 當男人戀愛時", | ||
"Goddamned Asura / 該死的阿修羅", | ||
"Gaga / 哈勇家", | ||
"Incantation / 咒", | ||
"The Post-Truth World / 罪後真相", | ||
"The Pig, the Snake and the Pigeon / 周處除三害", | ||
"Taiwan Crime Stories / 台灣犯罪故事", | ||
) | ||
|
||
# MOVIE_CHOICES = [ | ||
# Choice(name=movie_name, value=movie_name) for movie_name in LIST_OF_MOVIES | ||
# ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.