-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.py
More file actions
93 lines (83 loc) · 2.54 KB
/
timer.py
File metadata and controls
93 lines (83 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from discord.ext import commands,tasks
from os import getenv
import discord
import traceback
import ffmpeg
import asyncio
import time
bot = commands.Bot(command_prefix='/')
@bot.event
async def on_ready():
print("on_ready")
print(bot.user.name) #bot name
print(bot.user.id) #ID
print(discord.__version__) #discord.pyのversion
print("--------")
await bot.change_presence(activity=discord.Game(name = "under development"))
@bot.event
async def on_command_error(ctx, error):
orig_error = getattr(error, "original", error)
error_msg = ''.join(traceback.TracebackException.from_exception(orig_error).format())
print(error_msg)
@bot.command()
async def leave(ctx):
if ctx.guild.voice_client is None:
await ctx.channel.send("接続していません")
return
#VC切断
await ctx.guild.voice_client.disconnect()
task = None
@bot.command()
async def set(ctx,alarm):
if ctx.guild.voice_client is None:
#VC接続
await ctx.author.voice.channel.connect()
#停止処理
global task
print(task)
task = asyncio.current_task()
#タイマーセット/アラーム
hmlist = countdowntime(alarm)
timer = hmlist[0] * 3600 + hmlist[1] * 60
await ctx.channel.send(f'{ctx.author.mention} タイマーを{timer}秒後にセットしました')
await asyncio.sleep(timer)
ctx.guild.voice_client.play(discord.FFmpegPCMAudio("shiningStar.mp3"))
await ctx.channel.send(f'{ctx.author.mention} {timer}秒が経過しました')
@bot.command()
async def stop(ctx):
global task
if task != None:
await ctx.channel.send('タイマーを停止しました')
task.cancel()
task = None
def countdowntime(alarm):
counter = 0
counth = 0
hour = False
minute = False
for i in alarm:
if i == 'h':
hour = True
counth = counter
alarmh = int(alarm[0:counth])
elif i == 'm' and counth == 0:
minute = True
countm = counter
alarmm = int(alarm[counth:countm])
elif i == 'm' and counth != 0:
minute = True
countm = counter
alarmm = int(alarm[counth+1:countm])
counter = counter + 1
if hour == True and minute == True:
return alarmh,alarmm
elif hour == True and minute == False:
return alarmh,0
elif hour == False and minute == True:
return 0,alarmm
else:
return 0,0
#botの起動とDiscordサーバーへの接続
#botのトークン
token = getenv('Token')
bot.run(token)