-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
148 lines (117 loc) Β· 5.88 KB
/
bot.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
import random, os, discord, json, asyncio
from datetime import datetime
from discord.ext import commands
from dotenv import load_dotenv
ECHO_CHANNEL_ID = 1300604396555731074 #wolves-alliance
DESTINATION_CHANNEL_IDS = [
1300604396555731074, # Wolves of War
1300609238023934042, # Redmoon Cult
1300646389155627069, # OneMillionBears
1306815142125637633, # Debaucherie
# Add more destination channels as needed
]
# Load environment variables
load_dotenv('bot_config.env')
token = os.getenv("DISCORD_TOKEN")
# Configure bot intents
intents = discord.Intents.default()
intents.reactions = True
intents.messages = True # Ensure the bot can read messages
intents.message_content = True
# Initialize the bot
bot = commands.Bot(command_prefix="!", intents=intents, case_insensitive=True)
# Dictionary to store winners and roll numbers
winners = {}
roll_numbers = {} # To track roll numbers per loot roll session
@bot.event
async def on_ready():
print(f'Logged in as {bot.user}')
@bot.command(name="lootroll", description="React to participate in loot roll for a specific item with a timer")
async def lootroll(ctx, item: str, time: int = 30):
# Initialize roll numbers for this item
roll_numbers[item] = {}
message = await ctx.send(f"π° Time to get rich! React with π² to claim the **{item}**! β³ Time left: {time} seconds!")
await message.add_reaction("π²")
await asyncio.sleep(time) # Wait for the set time
reaction_message = await ctx.channel.fetch_message(message.id)
reaction = discord.utils.get(reaction_message.reactions, emoji="π²")
if not reaction:
await ctx.send(f"π No reactions found for the **{item}**. Better luck next time!")
return
users = [user async for user in reaction.users()]
users = [user for user in users if user != bot.user]
if not users:
await ctx.send(f"π Nobody reacted for the **{item}**. Try again next time!")
return
# Assign random roll numbers (between 1 and 100) to users
for user in users:
roll_value = random.randint(1, 100) # Generate a random roll number
roll_numbers[item][user.name] = roll_value
await ctx.send(f"π² {user} rolled a {roll_value}.")
winner_name = max(roll_numbers[item], key=roll_numbers[item].get) # Get the user with the highest roll
roll_value = roll_numbers[item][winner_name]
if item not in winners:
winners[item] = []
winners[item].append(f"{winner_name} (Roll #{roll_value})")
# List of random emojis for winner announcement
winner_emojis = ["π", "π", "π", "π₯", "πΊ", "πΊ", "π£", "π₯"]
random_emoji = random.choice(winner_emojis) # Randomly select a winner emoji
await ctx.send(f"Congratulations {winner_name}! You won the **{item}** with Roll #{roll_value}! {random_emoji}") # Winner emoji
# Lock the reactions by removing the bot's own reaction
await message.clear_reactions() # This line will remove all reactions after the roll is done
@bot.command(name="clearall", description="Clear all messages in the channel (up to 100).")
@commands.has_permissions(manage_messages=True)
@commands.cooldown(1, 60, commands.BucketType.channel) # Limit to 1 use per channel every 60 seconds
async def clearall(ctx):
await ctx.channel.purge(limit=100) # Adjust the limit as needed (up to 100)
await ctx.send("π§Ή Cleared all messages!", delete_after=5) # Message will disappear after 5 seconds
@clearall.error
async def clearall_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(f"This command is on cooldown. Please wait {int(error.retry_after)} seconds before using it again.")
@bot.command(name="announce", description="Sends an announcement to our alliance partners.")
@commands.has_permissions(manage_messages=True)
async def announce(ctx, *args):
# Combine all arguments into a single string
announcement_text = " ".join(args)
# Send the announcement to each specified channel
not_found_channels = []
for channel_id in DESTINATION_CHANNEL_IDS:
destination_channel = bot.get_channel(channel_id)
if destination_channel:
# Relay the message to each destination channel
await destination_channel.send(f"πΊ **ALLIANCE UPDATE:** {announcement_text}")
else:
not_found_channels.append(channel_id)
# Notify if any channels could not be found
if not_found_channels:
await ctx.send(f"Could not find the following channels: {', '.join(map(str, not_found_channels))}")
@bot.event
async def on_message(message):
# Ignore messages from the bot itself
if message.author == bot.user:
return
# Check if the message was sent in one of the monitored channels
if message.channel.id in DESTINATION_CHANNEL_IDS:
# Loop through each channel in DESTINATION_CHANNEL_IDS
for channel_id in DESTINATION_CHANNEL_IDS:
# Skip the channel where the message was sent
if channel_id != message.channel.id:
# Get the target channel to echo the message to
target_channel = bot.get_channel(channel_id)
if target_channel:
# Forward the message content to the target channel
await target_channel.send(
f"π’ **Message from {message.author.display_name} in {message.channel.name}:** {message.content}"
)
# Ensure other commands can still function
await bot.process_commands(message)
@announce.error
async def announce_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You don't have permission to use this command.")
elif isinstance(error, commands.BotMissingPermissions):
await ctx.send("I don't have permission to perform this action.")
else:
await ctx.send("An error occurred while running the command.")
bot.run(token)