Skip to content

Commit

Permalink
Merge pull request #11 from nsslums/fix-ohiru
Browse files Browse the repository at this point in the history
fix ohiru && reformat files
  • Loading branch information
pantyetta authored Jun 24, 2024
2 parents 0f0dc61 + 85fe00b commit 749ac95
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
python/__pycache__/
python/.idea
.venv
2 changes: 2 additions & 0 deletions python/Bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
from discord import app_commands
import env
import pantyetta
import ohiru


intents = discord.Intents.default()#適当に。
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)

pantyetta.init(tree)
ohiru.init(tree)


@tree.command(name="ping",description="descriptioin")
Expand Down
46 changes: 46 additions & 0 deletions python/ohiru.py
Original file line number Diff line number Diff line change
@@ -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)
47 changes: 0 additions & 47 deletions python/pantyetta.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,11 @@
import discord
import calendar
from datetime import datetime, timedelta, timezone

def init(tree_bot):
tree = 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):
Expand Down
1 change: 1 addition & 0 deletions sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TOKEN="********************"

0 comments on commit 749ac95

Please sign in to comment.