Skip to content

Commit

Permalink
Merge pull request #26 from SCAICT/development
Browse files Browse the repository at this point in the history
Update Discord link and fix success page template + 剪刀石頭布
  • Loading branch information
iach526526 authored Mar 31, 2024
2 parents b46b8f6 + a656721 commit 67e3af4
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 中電喵 SCAICT uwu
A can living in SCAICT Discord Group

[![Sync issues to Notion](https://github.com/SCAICT/SCAICT-uwu/actions/workflows/notion.yml/badge.svg?event=issues)](https://github.com/SCAICT/SCAICT-uwu/actions/workflows/notion.yml)

![](thumbnail.png)

> This project is still in beta. If you have any problem, it works on my machine.
Expand Down
60 changes: 60 additions & 0 deletions cog/game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import discord
from discord.ext import commands
import os
import json
from cog.core.SQL import write
from cog.core.SQL import read
from cog.core.SQL import linkSQL
from cog.core.SQL import end
import random

def getChannels():#要特殊用途頻道的列表,這裡會用來判斷是否在簽到頻簽到,否則不予授理

with open(f"{os.getcwd()}/DataBase/server.config.json", "r") as file:
return json.load(file)["SCAICT-alpha"]

stickers = getChannels()["stickers"]['logo']

class game(commands.Cog):
# User can use this command to play ✊-🤚-✌️ with the bot in the command channel
@discord.slash_command(name="rock_paper_scissors", description="玩剪刀石頭布")
# useser can choose ✊, 🤚, or ✌️ in their command
async def rock_paper_scissors(self, interaction, choice: discord.Option(str, choices=["✊", "🤚", "✌️"])):
if (interaction.channel.id!=getChannels()["channel"]["commandChannel"]):
await interaction.response.send_message("這裡不是指令區喔")
return
userId = interaction.user.id
CONNECTION,CURSOR=linkSQL()#SQL 會話
userId = interaction.user.id
point = read(userId,'point',CURSOR)
if point<5:
await interaction.response.send_message("你的電電點不足以玩這個遊戲")
end(CONNECTION,CURSOR)
return
if choice not in ["✊", "🤚", "✌️"]:
await interaction.response.send_message("請輸入正確的選擇")
end(CONNECTION,CURSOR)
return
botChoice = random.choice(["✊", "🤚", "✌️"])
print(botChoice)
game_outcomes = {
("✌️", "✊"): 5,
("✌️", "🤚"): -5,
("✊", "✌️"): -5,
("✊", "🤚"): 5,
("🤚", "✌️"): 5,
("🤚", "✊"): -5,
}

if botChoice == choice:
await interaction.response.send_message(content=f"我出{botChoice},平手。你還有{point}{stickers}")
else:
point += game_outcomes[(botChoice, choice)]
result = "你贏了" if game_outcomes[(botChoice, choice)] > 0 else "你輸了"
await interaction.response.send_message(content=f"我出{botChoice}{result},你還有{point}{stickers}")
print(f"{userId},{nickName} Get {game_outcomes[(botChoice, choice)]} point by playing rock-paper-scissors")
write(userId, 'point',point ,CURSOR)
end(CONNECTION,CURSOR)

def setup(bot):
bot.add_cog(game(bot))
2 changes: 1 addition & 1 deletion templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<body>
<nav>
<a href="/"><i class="fa-solid fa-store"></i> 商店</a>
<a href="https://discord.com/invite/neQ7QEUcqe"><i class="fa-brands fa-discord"></i>回到 Discord</a>
<a href="dc.scaict.org"><i class="fa-brands fa-discord"></i>回到 Discord</a>
{% if ticket %}
<div class="ticket">{{ ticket }} 🎟️</div>
{% endif %} {% if point %}
Expand Down
2 changes: 1 addition & 1 deletion templates/slot.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
<body>
<nav>
<a href="/"><i class="fa-solid fa-store"></i> 商店</a>
<a href="https://discord.com/invite/neQ7QEUcqe"><i class="fa-brands fa-discord"></i>回到 Discord</a>
<a href="https://dc.scaict.org"><i class="fa-brands fa-discord"></i>回到 Discord</a>
{% if ticket %}
<div class="ticket">{{ ticket }} 🎟️</div>
{% endif %} {% if point %}
Expand Down
File renamed without changes.

0 comments on commit 67e3af4

Please sign in to comment.