Upload to gitea
This commit is contained in:
commit
d3d25c68f9
12 files changed
+500
No files matched your search
@@ -0,0 +1,51 @@
|
||||
from datetime import datetime
|
||||
|
||||
import discord
|
||||
from discord import app_commands
|
||||
from discord.ext import commands
|
||||
|
||||
import db
|
||||
from config import TZ
|
||||
|
||||
|
||||
class Signin(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, message: discord.Message):
|
||||
if message.author.bot or not message.guild:
|
||||
return
|
||||
guild_id = message.guild.id
|
||||
if message.channel.id != db.get_setting(guild_id, "signin_channel"):
|
||||
return
|
||||
if message.content.strip() != db.get_setting(guild_id, "signin_text"):
|
||||
return
|
||||
|
||||
today = datetime.now(TZ).date().isoformat()
|
||||
with db.conn:
|
||||
signed = db.try_signin(
|
||||
guild_id, message.author.id, db.get_setting(guild_id, "signin_reward"), today
|
||||
)
|
||||
if not signed:
|
||||
return
|
||||
|
||||
try:
|
||||
await message.add_reaction(db.get_setting(guild_id, "signin_reaction"))
|
||||
except discord.HTTPException:
|
||||
pass # 表符失效(例如被刪除)時不影響簽到
|
||||
|
||||
@app_commands.command(name="餘額", description="查看自己的點數")
|
||||
@app_commands.guild_only()
|
||||
async def balance(self, interaction: discord.Interaction):
|
||||
user = interaction.user
|
||||
guild_id = interaction.guild_id
|
||||
await interaction.response.send_message(
|
||||
f"{user.mention} 目前有 {db.get_points(guild_id, user.id)} "
|
||||
f"{db.get_setting(guild_id, 'currency_name')}",
|
||||
allowed_mentions=discord.AllowedMentions.none(), # 公開訊息,不要 tag 到自己
|
||||
)
|
||||
|
||||
|
||||
async def setup(bot: commands.Bot):
|
||||
await bot.add_cog(Signin(bot))
|
||||
Reference in new issue
Block a user