diff --git a/.gitignore b/.gitignore index 8c406b8..e5f5960 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env python/__pycache__/ python/.idea +.venv \ No newline at end of file diff --git a/python/Bot.py b/python/Bot.py index 63c17d6..4abf313 100644 --- a/python/Bot.py +++ b/python/Bot.py @@ -2,6 +2,7 @@ from discord import app_commands import env import pantyetta +import ohiru intents = discord.Intents.default()#適当に。 @@ -9,6 +10,7 @@ tree = app_commands.CommandTree(client) pantyetta.init(tree) +ohiru.init(tree) @tree.command(name="ping",description="descriptioin") diff --git a/python/ohiru.py b/python/ohiru.py new file mode 100644 index 0000000..4b89a8e --- /dev/null +++ b/python/ohiru.py @@ -0,0 +1,46 @@ +import discord +import calendar +from datetime import datetime, timedelta, timezone + +def init(tree_bot): + tree = tree_bot + + # 何週目かを計算 + def week_count(day:datetime) -> int: + first_day_of_month = day.replace(day=1) + return (day - first_day_of_month).days // 7 + 1 + + def get_week(day): + now_week = week_count(day) + first_day_of_month = day.replace(day=1) + if first_day_of_month.weekday() > 0 : + now_week += 1 + return now_week + + def today(): + tz = timezone(timedelta(hours=9)) + return datetime.now(tz) + + def yearMonth(day): + now_week = week_count(day) + first_day_of_month = day.replace(day=1) + if now_week == 1 and first_day_of_month.weekday() > 0: + old_day = day.replace(day=1) - timedelta(days=1) + return str(old_day.strftime("%Y%m")) + return str(day.strftime("%Y%m")) + + @tree.command(name="ohiru",description="weekly launch menu.") + async def ohiru(interaction: discord.Interaction, private: bool = True): + date = today() + image_url = f'https://www.cit-s.com/wp/wp-content/themes/cit/menu/td_{str(yearMonth(date))}_{str(get_week(date))}.png' + embed = discord.Embed(title="今週のメニュー", color=0x3c0fbc) + embed.set_image(url=image_url) + await interaction.response.send_message(embed=embed, ephemeral=private) + + @tree.command(name="gomi",description="View garbage live.") + async def gomi(interaction: discord.Interaction, private: bool = True): + date = today() + image_url='https://www.cit-s.com/i_catch/dining/tsudanuma.jpg?' + str(date.strftime("%Y%m%d%H%M%S")) + embed=discord.Embed(title= "食堂の混雑状況", color=0x3c0fbc) + embed.set_image(url=image_url) # URLでEmbedに画像を貼る + await interaction.response.send_message(embed=embed, ephemeral=private) \ No newline at end of file diff --git a/python/pantyetta.py b/python/pantyetta.py index 516f991..80367c4 100644 --- a/python/pantyetta.py +++ b/python/pantyetta.py @@ -1,6 +1,4 @@ import discord -import calendar -from datetime import datetime, timedelta, timezone def init(tree_bot): tree = tree_bot @@ -8,51 +6,6 @@ def init(tree_bot): @tree.command(name="pantyetta", description="description") async def pantyetta(interaction: discord.Interaction, private: bool = True): await interaction.response.send_message("pancho", ephemeral=private) # ephemeral=True→「これらはあなただけに表示されています」 - - def get_last_week(year, month): - _, days_in_month = calendar.monthrange(year, month) - # 月の週数を計算 - weeks = (days_in_month + calendar.firstweekday() - 1) // 7 + 1 - return weeks - - def get_now_week(day): - first_day_of_month = day.replace(day=1) - # 今日が何週目かを計算 - return (day - first_day_of_month).days // 7 + 1 - - def get_week(day): - now_week = get_now_week(day) - if now_week == 1 and day.weekday() > 1: - old_day = day.replace(day=1) - timedelta(days=1) - now_week = get_last_week(old_day.year, old_day.month) - return now_week - - def today(): - tz = timezone(timedelta(hours=9)) - return datetime.now(tz) - - def yearMonth(day): - now_week = get_now_week(day) - if now_week == 1 and day.weekday() > 1: - old_day = day.replace(day=1) - timedelta(days=1) - return str(old_day.strftime("%Y%m")) - return str(day.strftime("%Y%m")) - - @tree.command(name="ohiru",description="weekly launch menu.") - async def ohiru(interaction: discord.Interaction, private: bool = True): - date = today() - image_url = 'https://www.cit-s.com/wp/wp-content/themes/cit/menu/td_' + yearMonth(date) + '_' + str(get_week(date)) + '.png' - embed = discord.Embed(title="今週のメニュー", color=0x3c0fbc) - embed.set_image(url=image_url) - await interaction.response.send_message(embed=embed, ephemeral=private) - - @tree.command(name="gomi",description="View garbage live.") - async def gomi(interaction: discord.Interaction, private: bool = True): - date = today() - image_url='https://www.cit-s.com/i_catch/dining/tsudanuma.jpg?' + str(date.strftime("%Y%m%d%H%M%S")) - embed=discord.Embed(title= "食堂の混雑状況", color=0x3c0fbc) - embed.set_image(url=image_url) # URLでEmbedに画像を貼る - await interaction.response.send_message(embed=embed, ephemeral=private) @tree.command(name="masa",description="descriptioin") async def masa(interaction: discord.Interaction, private: bool = False): diff --git a/sample.env b/sample.env new file mode 100644 index 0000000..a242cc8 --- /dev/null +++ b/sample.env @@ -0,0 +1 @@ +TOKEN="********************" \ No newline at end of file