Skip to content

Commit e803c20

Browse files
committed
Added giveaways, Wiki & Updated README.md
In this update we've added giveaways (finnaly) and updated README. The wiki is still in progress though should be ready soon.
1 parent 5742492 commit e803c20

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# UltimateCoreBot
2-
This bot will help you manage your server, its a self-hosted bot which does everything.
2+
This bot will help you manage your server efficiently.
3+
4+
# Getting Started
5+
* **[Setting up the bot](https://github.com/NeilDevolopment/UltimateCoreBot/wiki/Setup)**
6+
* **[Updating the bot](https://github.com/NeilDevolopment/UltimateCoreBot/wiki/Updating)**
7+
* [Configuration](https://github.com/NeilDevolopment/UltimateCoreBot/wiki/Configuration)
8+
* [Commands](https://github.com/NeilDevolopment/UltimateCoreBot/wiki/Commands)

cogs/fun.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ def __init__(self, client):
66
self.bot = client
77

88

9+
910
def setup(client):
1011
client.add_cog(Fun(client))

cogs/giveaway.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,100 @@
11
from discord.ext import commands
2+
import os
3+
import random
4+
import asyncio
25

36
class Giveaway(commands.Cog):
47

58
def __init__(self, client):
69
self.bot = client
10+
admin_role = os.getenv("ADMIN_ROLE")
711

12+
def convert(time):
13+
pos = ["s","m","h","d"]
14+
15+
time_dict = {"s" : 1, "m" : 60, "h" : 3600 , "d" : 3600*24}
16+
17+
unit = time[-1]
18+
19+
if unit not in pos:
20+
return -1
21+
try:
22+
val = int(time[:-1])
23+
except:
24+
return -2
25+
26+
27+
return val * time_dict[unit]
28+
29+
@commands.command()
30+
@commands.has_role()
31+
async def giveaway(ctx):
32+
await ctx.send("Let's start with this giveaway! Answer these questions within 15 seconds!")
33+
34+
questions = ["Which channel should it be hosted in?",
35+
"What should be the duration of the giveaway? (s|m|h|d)",
36+
"What is the prize of the giveaway?"]
37+
38+
answers = []
39+
40+
def check(m):
41+
return m.author == ctx.author and m.channel == ctx.channel
42+
43+
for i in questions:
44+
await ctx.send(i)
45+
46+
try:
47+
msg = await client.wait_for('message', timeout=15.0, check=check)
48+
except asyncio.TimeoutError:
49+
await ctx.send('You didn\'t answer in time, please be quicker next time!')
50+
return
51+
else:
52+
answers.append(msg.content)
53+
try:
54+
c_id = int(answers[0][2:-1])
55+
except:
56+
await ctx.send(f"You didn't mention a channel properly. Do it like this {ctx.channel.mention} next time.")
57+
return
58+
59+
channel = client.get_channel(c_id)
60+
61+
time = convert(answers[1])
62+
if time == -1:
63+
await ctx.send(f"You didn't answer the time with a proper unit. Use (s|m|h|d) next time!")
64+
return
65+
elif time == -2:
66+
await ctx.send(f"The time must be an integer. Please enter an integer next time")
67+
return
68+
69+
prize = answers[2]
70+
71+
await ctx.send(f"The Giveaway will be in {channel.mention} and will last {answers[1]}!")
72+
73+
74+
embed = discord.Embed(title = "Giveaway!", description = f"{prize}", color = ctx.author.color)
75+
76+
embed.add_field(name = "Hosted by:", value = ctx.author.mention)
77+
78+
embed.set_footer(text = f"Ends {answers[1]} from now!")
79+
80+
my_msg = await channel.send(embed = embed)
81+
82+
83+
await my_msg.add_reaction(":tada:")
84+
85+
86+
await asyncio.sleep(time)
87+
88+
89+
new_msg = await channel.fetch_message(my_msg.id)
90+
91+
92+
users = await new_msg.reactions[0].users().flatten()
93+
users.pop(users.index(client.user))
94+
95+
winner = random.choice(users)
96+
97+
await channel.send(f"Congratulations! {winner.mention} won {prize}!")
898

999
def setup(client):
10100
client.add_cog(Giveaway(client))

reveal_token.png

22.1 KB
Loading

0 commit comments

Comments
 (0)