MKE0108 commited on
Commit
cfc9a27
·
1 Parent(s): 5d8bd50
Files changed (3) hide show
  1. Dockerfile +2 -4
  2. app.py +7 -54
  3. bot_main.py +56 -0
Dockerfile CHANGED
@@ -1,6 +1,3 @@
1
- # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
- # you will also find guides on how best to write your Dockerfile
3
-
4
  FROM python:3.9
5
 
6
  RUN useradd -m -u 1000 user
@@ -13,4 +10,5 @@ COPY --chown=user ./requirements.txt requirements.txt
13
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
 
15
  COPY --chown=user . /app
16
- CMD ["python", "app.py"]
 
 
 
 
 
1
  FROM python:3.9
2
 
3
  RUN useradd -m -u 1000 user
 
10
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
 
12
  COPY --chown=user . /app
13
+ RUN python bot_main.py
14
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py CHANGED
@@ -1,56 +1,9 @@
1
- import discord
2
- from discord.ext import commands
3
  import os
4
- if(os.getenv('BOT_TOKENS') == None):
5
- from keys import init
6
- intents = discord.Intents.default()
7
- intents.message_content = True
8
 
9
- bot = commands.Bot(command_prefix='!', intents=intents)
10
-
11
- @bot.event
12
- async def on_ready():
13
- print(f'{bot.user} 已連線到 Discord!')
14
-
15
- @bot.command()
16
- async def synccommands(ctx):
17
- await bot.tree.sync()
18
- await ctx.send('同步完成')
19
-
20
- @bot.hybrid_command(description="這個指令會回覆你的問候")
21
- async def hello(ctx):
22
- await ctx.send(f'你好 {ctx.author.name}!')
23
-
24
- @bot.hybrid_command(description="測試延遲")
25
- async def ping(ctx):
26
- await ctx.send(f'Pong! 延遲: {round(bot.latency * 1000)}ms')
27
-
28
-
29
- @bot.hybrid_command(description="顯示機器人資訊")
30
- async def info(ctx):
31
- embed = discord.Embed(title="機器人資訊", color=0x00ff00)
32
- embed.add_field(name="名稱", value=bot.user.name, inline=True)
33
- embed.add_field(name="ID", value=bot.user.id, inline=True)
34
- embed.add_field(name="伺服器數量", value=len(bot.guilds), inline=True)
35
- await ctx.send(embed=embed)
36
-
37
- @bot.hybrid_command(description="抽路線指令, 用法: !pick 人名1 人名2 人名3 ...")
38
- async def pick(ctx,str):
39
- import random
40
- player = str.split(' ')
41
- if(len(player) > 5):
42
- await ctx.send('請輸入<5個人')
43
- return
44
- lane=["🗡️ 上路","💰 打野","🔮 中路","🏹 下路","🚑 輔助"]
45
- while(len(player) < 5):
46
- player.append("---")
47
- random.shuffle(player)
48
- embed = discord.Embed(title="抽獎結果", color=0x00ff00)
49
- for i in range(len(player)):
50
- embed.add_field(value=player[i], name=lane[i], inline=False)
51
- solgan = ["我從不覺得在召喚峽谷快樂過","一但加入了召喚峽谷就再也回不去了","我們的遊戲就是要讓你們不開心","你們的不開心就是我們的快樂","你們滿腦子只想著自己","還真是虛情假義呢"]
52
-
53
- await ctx.send(random.sample(solgan,1)[0],embed=embed)
54
-
55
-
56
- bot.run(os.getenv('BOT_TOKENS'))
 
1
+ from fastapi import FastAPI
 
2
  import os
3
+ app = FastAPI()
 
 
 
4
 
5
+ @app.get("/")
6
+ def greet_json():
7
+ #跑python bot_main.py
8
+ # os.system("python bot_main.py")
9
+ return {"Hello": "World!"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bot_main.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import discord
2
+ from discord.ext import commands
3
+ import os
4
+ if(os.getenv('BOT_TOKENS') == None):
5
+ from keys import init
6
+ intents = discord.Intents.default()
7
+ intents.message_content = True
8
+
9
+ bot = commands.Bot(command_prefix='!', intents=intents)
10
+
11
+ @bot.event
12
+ async def on_ready():
13
+ print(f'{bot.user} 已連線到 Discord!')
14
+
15
+ @bot.command()
16
+ async def synccommands(ctx):
17
+ await bot.tree.sync()
18
+ await ctx.send('同步完成')
19
+
20
+ @bot.hybrid_command(description="這個指令會回覆你的問候")
21
+ async def hello(ctx):
22
+ await ctx.send(f'你好 {ctx.author.name}!')
23
+
24
+ @bot.hybrid_command(description="測試延遲")
25
+ async def ping(ctx):
26
+ await ctx.send(f'Pong! 延遲: {round(bot.latency * 1000)}ms')
27
+
28
+
29
+ @bot.hybrid_command(description="顯示機器人資訊")
30
+ async def info(ctx):
31
+ embed = discord.Embed(title="機器人資訊", color=0x00ff00)
32
+ embed.add_field(name="名稱", value=bot.user.name, inline=True)
33
+ embed.add_field(name="ID", value=bot.user.id, inline=True)
34
+ embed.add_field(name="伺服器數量", value=len(bot.guilds), inline=True)
35
+ await ctx.send(embed=embed)
36
+
37
+ @bot.hybrid_command(description="抽路線指令, 用法: !pick 人名1 人名2 人名3 ...")
38
+ async def pick(ctx,str):
39
+ import random
40
+ player = str.split(' ')
41
+ if(len(player) > 5):
42
+ await ctx.send('請輸入<5個人')
43
+ return
44
+ lane=["🗡️ 上路","💰 打野","🔮 中路","🏹 下路","🚑 輔助"]
45
+ while(len(player) < 5):
46
+ player.append("---")
47
+ random.shuffle(player)
48
+ embed = discord.Embed(title="抽獎結果", color=0x00ff00)
49
+ for i in range(len(player)):
50
+ embed.add_field(value=player[i], name=lane[i], inline=False)
51
+ solgan = ["我從不覺得在召喚峽谷快樂過","一但加入了召喚峽谷就再也回不去了","我們的遊戲就是要讓你們不開心","你們的不開心就是我們的快樂","你們滿腦子只想著自己","還真是虛情假義呢"]
52
+
53
+ await ctx.send(random.sample(solgan,1)[0],embed=embed)
54
+
55
+
56
+ bot.run(os.getenv('BOT_TOKENS'))