-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
141 lines (88 loc) · 3.31 KB
/
main.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Импортируем настройки бота
try:
import conf
except ImportError:
pass
import discord
from discord.ext import commands
import img_handler as imhl
import os, random
# # Настройки INTENTS
intentse = discord.Intents.default()
intentse.members = True
bot = commands.Bot(command_prefix = "!", intents = intentse)
whitelist = {
825328622654193675 : {825328622654193675: "Bots /general"},
}
# Декоратор - проверка @allowed_channel => True/False
def allowed_channel():
async def predicate(ctx:commands.Context):
if ctx.guild.id in whitelist:
if ctx.channel.id in whitelist[ctx.guild.id]:
return True
return False
return commands.check(predicate)
@bot.command(name="get_member")
async def get_member(ctx, member:discord.Member=None):
msg = None
global channel
if ctx.channel.id == channel:
if member:
msg = f'Member {member.name} {"({member.nick})" if member.nick else ""} - {member.id}'
if msg == None:
msg = "error"
await ctx.channel.send(msg)
#команда !mk
@bot.command(name="mk")
async def mk(ctx,f1:discord.Member=None,f2:discord.Member=bot.user):
global channel
if ctx.channel.id == channel:
if f1 and f2:
await imhl.vs_create_animated(f1.avatar_url, f2.abatar_url)
await ctx.channel.send( file=discord.File(os.path.join("./img/result.gif")) )
@bot.command(name="join")
@allowed_channel()
async def vs_join(ctx):
global channel
if ctx.channel.id == channel:
voice_channel = ctx.author.voice.channel
if voice_channel:
msg =f"Подключаюсь к {voice_channel.name}"
await ctx.channel.send( msg )
await voice_channel.connect()
@bot.command(name="leave")
async def vs_leave(ctx):
msg =""
global channel
voice_channel = ctx.author.voice.channel
if voice_channel and ctx.channel.id == channel:
voice_channel = ctx.author.voice.channel
msg =f"Отключаюсь от {voice_channel.name}"
await ctx.channel.send( msg )
await voice_client.disconnect()
@bot.command(name="ost")
async def vs_ost(ctx):
msg = ""
global channel
if ctx.channel.id == channel:
voice_client = discord.utils.get(bot.voice_clients, guild = ctx.guild)
msg = f"Mortal Kombat"
await ctx.channel.send(msg)
await voice_client.play(discord.FFmpegPCMAudio(source = "./sound/mk.mp3"))
@bot.command(name="fight")
@allowed_channel()
async def fight(ctx,f1:discord.Member=None,f2:discord.Member=bot.user):
f1 = None
f2 = bot.user
voice_channel = ctx.author.voice.channel
if voice_channel:
await vc_join(ctx)
voice_members = voice_channel.members
voice_members = [member for member in voice_members if member.bot == False]
if len(voice_members) > 1:
f1,f2 = [voice_members.pop(random.randit(0, len(voice_members)-1)), voice_members.pop(random.randit(0, len(voice_members)-1))]
else:
f1 = ctx.author
await imhl.vs_create_animated(f1.avatar_url, f2.abatar_url)
await ctx.channel.send( file=discord.File(os.path.join("./img/result.gif")) )
bot.run(os.environ["BOT_TOKEN"])