Skip to content

Commit

Permalink
Merge pull request #56 from SCAICT/development
Browse files Browse the repository at this point in the history
五月更新
  • Loading branch information
Edit-Mr authored May 6, 2024
2 parents b3b1e92 + 1e7605d commit 84cebb8
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 22 deletions.
24 changes: 21 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,25 @@ for further information.

#### Database

ALWAYS use `snake_case` for database, table, column, trigger names.
* ALWAYS and ONLY capitalize SQL reserved words in SQL queries.
* See the official documentations of SQL and the
[complete list on English Wikipedia](https://en.wikipedia.org/wiki/List_of_SQL_reserved_words)
as references.
* ALWAYS use `snake_case` for database, table, column, trigger names.
* Table names and column names may NOT be case-sensitive in SQLite.
* Database, table, and trigger names may NOT be case-sensitive in
MySQL/MariaDB.
* Column names should be unique, i.e., same column name should not exist in
different tables.
* Column names should be prefixed with table names or abbrieviations.
* For example, `user_id` in `user`, `ug_user` in `user_groups`.

Examples:

```sql
INSERT INTO user (uid) VALUE (6856)
```

* Table names and column names may NOT be case-sensitive in SQLite.
* Database, table, and trigger names may NOT be case-sensitive in MySQL/MariaDB.
```sql
UPDATE game SET game_seq = game_seq + 1
```
4 changes: 3 additions & 1 deletion DataBase/server.config-alpha.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"pointCount": 1206549021355810816,
"everyDayCharge": 1206549724530999356,
"commandChannel": 1206550021353242654,
"countChannel": 1220130492821667973
"countChannel": 1220130492821667973,
"colorChannel": 1225850293762134036,
"exclude_point":[1220130492821667973,1225850293762134036]
},
"SP-role": {
"CTF_Maker": 1210935361467977738
Expand Down
2 changes: 1 addition & 1 deletion DataBase/server.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"commandChannel": 1215248945601712158,
"countChannel": 1219615518974148638,
"colorChannel": 1225869655093284927,
"exclude_point": [1219615518974148638, 1215248450502008832]
"exclude_point": [1219615518974148638,1225869655093284927]
},
"SP-role": {
"CTF_Maker": 1215248450502008832
Expand Down
67 changes: 50 additions & 17 deletions cog/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import timedelta
import json
import os
import re
# Third-party imports
import discord
from discord.ext import commands
Expand Down Expand Up @@ -75,17 +76,14 @@ async def on_message(self, message):
url = f"{arg[2]}"
# , details = f"{arg[1]}"
))
if userId != self.bot.user.id:
# 機器人會想給自己記錄電電點,必須排除
if message.channel.id == self.sp_channel["countChannel"]:
# 數數回應
await Comment.count(message)
elif message.channel.id == self.sp_channel["colorChannel"]:
#猜色碼回應
await Comment.niceColor(message)
return
if message.channel.id not in self.sp_channel["exclude_point"]:
# 列表中頻道不算發言次數
if message.channel.id == self.sp_channel["countChannel"]:
# 數數回應
await Comment.count(message)
elif message.channel.id == self.sp_channel["colorChannel"]:
#猜色碼回應
await Comment.niceColor(message)
if message.channel.id not in self.sp_channel["exclude_point"] and userId != self.bot.user.id:
# 列表中頻道不算發言次數 # 機器人會想給自己記錄電電點,必須排除
Comment.today_comment(userId, message, CURSOR)
end(CONNECTion, CURSOR)

Expand All @@ -109,9 +107,43 @@ def today_comment(userId, message, CURSOR):
async def count(message):
CONNECT, CURSOR = link_sql()
try:
bin_string = message.content
#若bin_string轉換失敗,會直接跳到except
decimal_number = int(bin_string, 2)
raw_content = message.content
counting_base = 9

# Allow both plain and monospace formatting
based_number = re.sub("^`([^\n]+)`$", "\\1", raw_content)

# If is valid 4-digit whitespace delimeter format
# (with/without base), then strip whitespace characters.
#
# Test cases:
# - "0"
# - "0000"
# - "000000"
# - "00 0000"
# - "0b0"
# - "0b0000"
# - "0b 0000"
# - "0b0 0000"
# - "0b 0 0000"
# - "0 b 0000"
# - "0 b 0 0000"
if re.match(
"^(0[bdox]|0[bdox] |0 [bdox] |)" +
"([0-9A-Fa-f]{1,4})" +
"(([0-9A-Fa-f]{4})*|( [0-9A-Fa-f]{4})*)$",
based_number
):
based_number = based_number.replace(" ", "")
# If is valid 3-digit comma delimeter format
# (10-based, without base)
elif (
counting_base == 10 and
re.match("^([0-9]{1,3}(,[0-9]{3})*)$", based_number)
):
based_number = based_number.replace(",", "")
# 若based_number字串轉換至整數失敗,會直接跳到except
decimal_number = int(based_number, counting_base)
CURSOR.execute("select seq from game")
now_seq = CURSOR.fetchone()[0]
CURSOR.execute("select lastID from game")
Expand All @@ -125,12 +157,13 @@ async def count(message):
CURSOR.execute(f"UPDATE game SET lastID = {message.author.id}")
# add a check emoji to the message
await message.add_reaction("✅")
# 隨機產生 1~100 的數字。若介於 1~3 之間,則給予 5 點電電點
if random.randint(1, 100) <= 3:
# 隨機產生 1~100 的數字。若模 11=10 ,九個數字符合,分布於 1~100 ,發生機率 9%。給予 5 點電電點
rand = random.randint(1, 100)
if rand%11 == 10:
point = read(message.author.id, "point", CURSOR) + 5
write(message.author.id, "point", point, CURSOR)
print(f"{message.author.id},{message.author} Get 5 point by count reward {datetime.now()}")
await message.add_reaction(":moneybag:")
await message.add_reaction("💸")
else:
# 不同人數數,但數字不對
await message.add_reaction("❌")
Expand Down

0 comments on commit 84cebb8

Please sign in to comment.