-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
112 lines (87 loc) · 3.44 KB
/
utils.py
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import discord
import commands.join as join
from commands.log import log_error
numbers_emoji = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"]
async def return_number_to_emoji():
global numbers_emoji
return numbers_emoji
async def embedded_message(ctx, title, description):
embed = discord.Embed(title=title, description=description, color=discord.Color.red())
embed.set_footer(text=" Resquested by " + ctx.message.author.name, icon_url=ctx.message.author.avatar)
await ctx.channel.send(embed=embed)
def get_time_in_seconds(time: str):
# Only seconds
try:
time = int(time)
return time
# hh:mm:ss format
except:
time_size = len(time)
try:
seconds = int(time[time_size - 2:])
if time_size == 4:
minutes = int(time[time_size - 4])
else:
minutes = int(time[time_size - 5:time_size - 3])
time_in_secs = 60 * minutes + seconds
# mm:ss format
if time_size < 6:
return time_in_secs
# hh:mm:ss format
if time_size == 7:
hours = int(time[time_size - 7])
else:
hours = int(time[time_size - 8:time_size - 6])
return 60 * 60 * hours + time_in_secs
except:
log_error("seek", "Unable to convert number to seconds")
return None
def format_time(time):
seconds = format_subtime(str(time % 60))
# Time is less than an hour
if time < 3600:
minutes = format_subtime(str(time // 60))
return minutes + ":" + seconds
# Time is more than an hour
minutes = format_subtime(str(time // 60 % 60))
hours = format_subtime(str(time // 3600))
return hours + ":" + minutes + ":" + seconds
def format_subtime(subtime):
if len(subtime) == 0:
return "00"
elif len(subtime) == 1:
return "0" + subtime
else:
return subtime
async def verify_channel(ctx, sender_equals_bot: bool = True):
sender = ctx.author.voice
if not sender:
await embedded_message(ctx, ":exclamation: **Not Connected**", "_You must be connected to a voice channel_")
return False
sender_channel = sender.channel
if sender_equals_bot:
if ctx.guild.voice_client:
bot_channel = ctx.guild.voice_client.channel
if bot_channel != sender_channel:
await embedded_message(ctx, "**Foreign detected :ghost:**", "_You must be in the same channel_\n" +
"_as the bot to issue this command_")
return False
else:
await embedded_message(ctx, ":exclamation: **Not Connected**", "_I'm currently not connected_")
return False
return True
async def verify_channel_play(ctx):
sender = ctx.author.voice
if not sender:
await embedded_message(ctx, ":exclamation: **Not Connected**", "_You must be connected to a voice channel_")
return False
sender_channel = sender.channel
bot_channel = ctx.guild.voice_client
if bot_channel:
if bot_channel.channel == sender_channel:
return True
await embedded_message(ctx, "**Foreign detected :ghost:**", "_You must be in the same channel_\n" +
"_as the bot to issue this command_")
return False
await join.join_channel(ctx)
return True