-
Notifications
You must be signed in to change notification settings - Fork 0
/
test10.py
204 lines (183 loc) · 8.9 KB
/
test10.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
from flask import Flask
import threading
import discord
from discord.ext import commands
from discord import app_commands
# Flask app setup
app = Flask(__name__)
# Discord bot setup
intents = discord.Intents.default()
intents.messages = True
intents.guilds = True
bot = commands.Bot(command_prefix='/', intents=intents)
bot_running = False
bot_error_message = None
# Variables to store the channels in which commands are allowed
player_search_channel_id = None
clan_search_channel_id = None
# Bot event and command setup
@bot.event
async def on_ready():
global bot_running, bot_error_message
bot_running = True
bot_error_message = None
print(f'Logged in as {bot.user.name}')
@bot.event
async def on_disconnect():
global bot_running, bot_error_message
bot_running = False
bot_error_message = "Bot disconnected unexpectedly."
print(bot_error_message)
def is_bot_manager():
async def predicate(interaction: discord.Interaction):
return any(role.name == "Bot Manager" for role in interaction.user.roles)
return commands.check(predicate)
def is_special_user(interaction):
if interaction.user.id == 649571921633083412:
return interaction.user.guild_permissions.administrator
return False
@app_commands.guilds(discord.Object(id=1213279065306431588))
@bot.tree.command(name="set_channel", description="Set the channels where commands are allowed")
@is_bot_manager()
async def set_channel(interaction: discord.Interaction, player_search: discord.TextChannel, clan_search: discord.TextChannel):
global player_search_channel_id, clan_search_channel_id
player_search_channel_id = player_search.id
clan_search_channel_id = clan_search.id
await interaction.response.send_message(f'Player search commands are now restricted to {player_search.mention}. Clan search commands are now restricted to {clan_search.mention}.')
def check_player_search_channel(interaction):
return player_search_channel_id and interaction.channel_id == player_search_channel_id
def check_clan_search_channel(interaction):
return clan_search_channel_id and interaction.channel_id == clan_search_channel_id
@app_commands.guilds(discord.Object(id=1213279065306431588))
@bot.tree.command(name="open_raid_post", description="Create a Raid Matcher post")
@app_commands.choices(
skill_level=[
app_commands.Choice(name="Amateur", value="Amateur"),
app_commands.Choice(name="Experienced", value="Experienced"),
app_commands.Choice(name="Professional", value="Professional")
],
clan_tag=[
app_commands.Choice(name="Lost F2P", value="Lost F2P #2820UPPQC"),
app_commands.Choice(name="Lost F2P 2", value="Lost F2P 2 #2LG222Q0L"),
app_commands.Choice(name="Lost 3", value="Lost 3 #2YUPV0UYC"),
app_commands.Choice(name="Lost 4", value="Lost 4 #2LU2V2LPU"),
app_commands.Choice(name="Lost 5", value="Lost 5 #2QC0QQPQ2"),
app_commands.Choice(name="Lost 6", value="Lost 6 #2YVPC20UY"),
app_commands.Choice(name="Lost 7", value="Lost 7 #2QQ29JCYV"),
app_commands.Choice(name="Lost GP", value="Lost GP #2YVJV8VC0"),
app_commands.Choice(name="MCG", value="MCG #2GJR8RJGC")
],
cg_donation=[
app_commands.Choice(name="0%", value="0%"),
app_commands.Choice(name="25%", value="25%"),
app_commands.Choice(name="50%", value="50%"),
app_commands.Choice(name="75%", value="75%"),
app_commands.Choice(name="100%", value="100%")
]
)
async def open_raid_post(
interaction: discord.Interaction,
clan_tag: str,
available_slots: int,
skill_level: str,
contact: str,
cg_donation: str,
extra_info: str = "No"
):
if not check_player_search_channel(interaction):
await interaction.response.send_message("This command is not allowed in this channel.")
return
embed = discord.Embed(title="Raid Matcher - Open Raid Spots", color=discord.Color.gold())
embed.add_field(name="Clan Tag", value=clan_tag, inline=False)
embed.add_field(name="Available Slots", value=str(available_slots), inline=False)
embed.add_field(name="Skill Level", value=skill_level, inline=False)
embed.add_field(name="Contact", value=contact, inline=False)
embed.add_field(name="CG Donation", value=cg_donation, inline=False)
embed.add_field(name="Additional Info", value=extra_info, inline=False)
embed.set_footer(text="Made by MCG Student")
await interaction.response.send_message(embed=embed)
@app_commands.guilds(discord.Object(id=1213279065306431588))
@bot.tree.command(name="raid_service_post", description="Create a Raid Service post")
@app_commands.choices(
skill_level=[
app_commands.Choice(name="Amateur", value="Amateur"),
app_commands.Choice(name="Experienced", value="Experienced"),
app_commands.Choice(name="Professional", value="Professional")
],
cg_donation=[
app_commands.Choice(name="0%", value="0%"),
app_commands.Choice(name="25%", value="25%"),
app_commands.Choice(name="50%", value="50%"),
app_commands.Choice(name="75%", value="75%"),
app_commands.Choice(name="100%", value="100%")
]
)
async def raid_service_post(
interaction: discord.Interaction,
player_tag: str,
skill_level: str,
contact: str,
cg_donation: str,
extra_info: str = "No",
number_of_accounts: int = 1
):
if not check_clan_search_channel(interaction):
await interaction.response.send_message("This command is not allowed in this channel.")
return
embed = discord.Embed(title="Raid Service - Player looking for Clan", color=discord.Color.gold())
embed.add_field(name="Player Tag", value=player_tag, inline=False)
embed.add_field(name="Skill Level", value=skill_level, inline=False)
embed.add_field(name="Contact", value=contact, inline=False)
embed.add_field(name="CG Donation", value=cg_donation, inline=False)
embed.add_field(name="Additional Info", value=extra_info, inline=False)
embed.add_field(name="Number of Accounts", value=str(number_of_accounts), inline=False)
embed.set_footer(text="Made by MCG Student")
await interaction.response.send_message(embed=embed)
'''@app_commands.guilds(discord.Object(id=1213279065306431588))
@bot.tree.command(name="bot_config", description="Konfiguration für RaidMatcher")
async def bot_config(interaction: discord.Interaction, clan_name: str, clan_tag: str):
# Überprüfen, ob der Nutzer die notwendigen Bedingungen erfüllt
if not is_special_user(interaction):
# Senden einer Fehlermeldung, wenn der Nutzer nicht autorisiert ist
await interaction.response.send_message("Dieser Command kann nur von einem speziellen Nutzer mit Adminrechten ausgeführt werden.", ephemeral=True)
return
# Command ausführen, wenn die Überprüfung erfolgreich war
await interaction.response.send_message(f"Command ausgeführt für Clan {clan_name} mit Tag {clan_tag}.")
'''
@app_commands.guilds(discord.Object(id=1213279065306431588)) # Set your guild ID(s) here
@bot.tree.command(name="stadtgold", description="Information über Stadtgold Spenden im Clan")
async def stadtgold(interaction: discord.Interaction):
embed = discord.Embed(
title="Stadtgold Spenden",
description="Es gibt keine Pflicht, wo du dein Stadtgold spenden musst. Trotzdem würden wir uns darüber freuen, wenn du dein Stadtgold im Clan MCG lässt.\n**#2GJR8RJGC; Clanlevel 7; grün-weißes Wappen**",
url="https://link.clashofclans.com/de?action=OpenClanProfile&tag=2GJR8RJGC",
color=discord.Color.green()
)
embed.set_footer(text="Made by MCG Student")
await interaction.response.send_message(embed=embed)
# Flask route definitions
@app.route('/')
def home():
if bot_running:
return "Hello from Flask! The Discord bot is running and connected."
elif bot_error_message:
return f"Hello from Flask! The Discord bot is not running. Error: {bot_error_message}"
else:
return "Hello from Flask! The Discord bot is not running and no specific error message is available."
# Function to run the Discord bot
def run_discord_bot():
try:
bot.run('YOUR_BOT_TOKEN') # Replace 'YOUR_BOT_TOKEN' with your actual Discord bot token.
except Exception as e:
global bot_running, bot_error_message
bot_running = False
bot_error_message = str(e) # Store the error message
print(f"Failed to start the bot: {e}")
# Main block to run the Flask app and Discord bot in separate threads
if __name__ == "__main__":
# Running the Discord bot in a separate thread
bot_thread = threading.Thread(target=run_discord_bot, daemon=True)
bot_thread.start()
# Running the Flask app
# Running the Flask app
app.run(host='0.0.0.0', port=8000, debug=True)