Skip to content

Commit e17b65f

Browse files
authored
Merge pull request #13 from Hjorthdx/Development-branch-v2.1
Development branch v2.1
2 parents 25800a8 + 696f9a4 commit e17b65f

31 files changed

Lines changed: 528 additions & 225 deletions

Constants.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
# CONSTANTS
2-
DEFAULT_WORKTIME = 50
3-
DEFAULT_BREAKTIME = 10
4-
DEFAULT_PLAYER_PATH = "C:/Program Files (x86)/ffmpeg/bin/ffmpeg.exe"
5-
SECONDS_IN_HOUR = 3600
6-
SECONDS_IN_MINUTE = 60
1+
WIKIPEDIA_RANDOM_LINK = "https://en.wikipedia.org/wiki/Special:Random"

Db.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
myClient = pymongo.MongoClient("mongodb://localhost:27017")
44
mydb = myClient["mydatabase"]
55
mycol = mydb["UserKarma"]
6+
pomodoroCol = mydb["Pomodoro"]
7+
8+
for document in mycol.find():
9+
print(document)
610

711
if not mycol.find():
812
karmaList = [

Player.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

Pomodoro.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# DiscordKarmaBot
2-
Discord bot that can keep track of user reactions. User reactions will be stored on a database in form of karma to see who is the meme lord.
3-
A player has been implemented that can play mp3 files to the users.
4-
Pomodoro timer is implemented, giving the users the ability to start timers, while working. When the time is up, the bot will join the room and play a mp3 files to alert the user, that the timer has ended.
5-
2+
Discord bot that can keep track of user reactions. User reactions will be stored on a database in form of karma.
3+
Can keep track of multiple pomodoro timers. Saves the timers in a database. Notifies when timer is up by playing mp3 files.
4+
Player cog that can play local mp3 files aswell as youtube links.
5+
Watch2gether cog to create watch2gether rooms with the desired video.

TODOS.txt

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,56 @@
11
# TODO
2+
# General things
3+
Tolower all user inputs, so they are not change sensitive.
4+
Make installation guide to use the bot
5+
6+
# USER CLASS
7+
Add default values for pomodoro timers, so every user can change their default with the !change default command.
8+
I think database, needs to keep track of the timer aswell, if that needs to be changed.
9+
210
# BOT PART
3-
(X) Bot skal forlade rummet selv efter mp3 fil er slut eller ved command måske.
4-
Change on_message !karma so it only needs to include !karma, so you could see karma of other users.
5-
E.g. !karma Hjorth - Would return the total karma of Hjorth no matter who the author is.
611
Needs to add highscores for both opdutter og neddutter.
712
Maybe give roles based on these, and let them update once someone else takes the lead.
813

914
# POMODORO PART
10-
(X) Pomodoro basic timer funcionality.
11-
(X) Pomodoro makes bot join and play sound when time is up.
12-
(X) Pomodoro default timers hvis andet ikke er specified.
13-
(X) Pomodoro !time så vi kan se hvor lang tid der er tilbage af en timer
14-
Let user change default timers for pomodoro, maybe something like !defaultbreak = something.
1515
User needs to be able to STOP the timer
1616
User needs to be able to PAUSE the timer
17-
17+
Make bot ask if you've forgotten to start timer. If there are like 5+ people in voice channel, then it should ask if a timer is needed
18+
Could be very helpful cause we always forgot those stupid timers
19+
https://discordpy.readthedocs.io/en/latest/api.html#voicechannel -> Members returns a list of all the users in a specific voice channel,
20+
maybe have some loop.wait_for(members.count >= 7) -> if timer not started, ask user if they want a timer started.
21+
https://discordpy.readthedocs.io/en/latest/api.html#discord.on_member_update USE THIS
22+
TALKED TO SIMON ABOUT THIS. THIS SHOULD WORK
23+
Comment inside pomodoro doucment needs to be done
24+
@everyone when timers are up.
25+
Needs to play in every room that there are peopple in
26+
When there is a break play the lofi radio
27+
1828
# PLAY PART
19-
(X) !play latex bastards - FILE ADDED.
20-
(X) !play bamse - DEN NYE POMODORO LYD.
2129
!play pomodoro lyd start/slut.
22-
(X) Maybe seperate file for alle playing, if it starts to grow any bigger.
23-
Makes the code more reable.
24-
It is growing out of hand, please make a new file that contains the playing part,
25-
so the if statements in bot is not so big.
26-
Maybe it can be abstracted more and the play document can handle which file to play.
27-
if "something" in message.content
28-
Player.Play(message) -> Some if chain in there that does the choosing of what to play.
29-
Only problem right now is that they are all different, !latex, !play, !inspiration etc.
30-
MAYBE !p inspiration, then that would be a lot simpler and a lot less if in the bot file.
3130
!play farvelsangen.
32-
(X) # Figure out some way to make it choose the channel with users in
33-
(X) !Motivationsbot - DU GØR DET OG DU GØR DET GODT.
31+
!p let me in
32+
Boomer alert
33+
Lofi radio
34+
35+
Player class that has playing status. If playing - then add it to queue, so it doesnt cause error everytime multiple people play audio clip.
36+
3437

3538
# DB
3639
Database skal sættes op til at være online - lav prio.
37-
Reset all the data in the database, cause sten's id is different from everyone elses,
38-
and it's pissing me off.
39-
Add collection for work/time.
40+
41+
# Wikipedia speedrun
42+
https://en.wikipedia.org/wiki/special:random - Gives a random wikipedia article
43+
Let players join the game before it starts.
44+
Start a timer on !start command
45+
!done command, that returns the time it has run.
46+
Possibly save this in database so we can have roles for this aswell.
47+
Et array med mulige ting vi skal finde - !add til listen.
48+
'
49+
50+
Add timer per user instead of name.
51+
52+
53+
# Notes to self
54+
# Help command
55+
Thing that deletes !help is in: class _HelpCommandImpl(Command): (line 182) in the prepare method.
56+
The thing that deletes the help message itself is in: class DefaultHelpCommand(HelpCommand): (line 996) in async def send_pages(self):

WikiSpeedrun.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
import Constants
3+
4+
class Speedrun:
5+
6+
def __init__(self, startingLink):
7+
self.startingLink = startingLink
8+
self.endLink = endLink
9+
self.participants = []
10+
11+
12+
13+
def addParticipant(self, user):
14+
self.participants.append(user)
15+
16+
def removeParticipant(self, user):
17+
self.participants.remove(user)
18+
19+
20+
21+
"""

__pycache__/Db.cpython-37.pyc

71 Bytes
Binary file not shown.

__pycache__/User.cpython-37.pyc

-2 Bytes
Binary file not shown.

bot.py

Lines changed: 22 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,32 @@
1-
import os, discord, pymongo, User, Db, threading, time, Pomodoro, Constants, Player
1+
import os, discord
22
from dotenv import load_dotenv
3-
3+
from discord.ext import commands
44
load_dotenv()
55

6-
# Emotes
7-
kurtApproved = 619818932475527210
8-
kurtDisapproved = 651028634945060864
9-
10-
#Instantiating all the users
11-
Adil = User.User('Adil', 100552145421467648, '100552145421467648')
12-
Chrille = User.User('Chrille', 279307446009462784, '279307446009462784')
13-
Hjorth = User.User('Hjorth', 140195461519769601, '140195461519769601')
14-
Martin = User.User('Martin', 103033943464353792, '502882469721407509')
15-
Magnus = User.User('Magnus', 272507977984901120, '272507977984901120')
16-
Simon = User.User('Simon', 619105357473775636, '619105357473775636')
17-
Sten = User.User('Sten', 502882469721407509, '502882469721407509')
18-
19-
users = [
20-
Adil,
21-
Chrille,
22-
Hjorth,
23-
Martin,
24-
Magnus,
25-
Simon,
26-
Sten
27-
]
28-
29-
client = discord.Client()
30-
31-
@client.event
32-
async def on_raw_reaction_add(payload):
33-
if payload.channel_id == 619105859615719434:
34-
if payload.emoji.id == kurtApproved:
35-
message = await client.http.get_message(payload.channel_id, payload.message_id) # Dictionary
36-
authorDict = message["author"]
37-
authorID = authorDict["id"] # String
38-
39-
for user in users:
40-
if user.strUserID == authorID and user.intUserID != payload.user_id:
41-
user.AddOpdut()
42-
elif user.strUserID == authorID and user.intUserID == payload.user_id:
43-
user.removeOpdut()
44-
user.removeOpdut()
45-
46-
elif payload.emoji.id == kurtDisapproved:
47-
message = await client.http.get_message(payload.channel_id, payload.message_id) # Dictionary
48-
authorDict = message["author"]
49-
authorID = authorDict["id"] # String
50-
51-
for user in users:
52-
if user.strUserID == authorID:
53-
user.AddNeddut()
54-
55-
@client.event
56-
async def on_raw_reaction_remove(payload):
57-
if payload.channel_id == 619105859615719434:
58-
if payload.emoji.id == kurtApproved:
59-
message = await client.http.get_message(payload.channel_id, payload.message_id) # Dictionary
60-
authorDict = message["author"]
61-
authorID = authorDict["id"] # String
62-
63-
for user in users:
64-
if user.strUserID == authorID and user.intUserID != payload.user_id:
65-
user.removeOpdut()
66-
elif user.strUserID == authorID and user.intUserID == payload.user_id:
67-
user.AddOpdut()
68-
user.AddOpdut()
69-
70-
elif payload.emoji.id == kurtDisapproved:
71-
message = await client.http.get_message(payload.channel_id, payload.message_id) # Dictionary
72-
authorDict = message["author"]
73-
authorID = authorDict["id"] # String
74-
75-
for user in users:
76-
if user.strUserID == authorID:
77-
user.removeNeddut()
78-
79-
@client.event
80-
async def on_message(message):
81-
if message.content == "!karma":
82-
for user in users:
83-
if message.author.id == user.intUserID:
84-
x = Db.mycol.find_one({ "Name": user.name })
85-
await message.channel.send('{} has {} total karma. {} opdutter and {} neddutter'.format(x["Name"], x["Opdutter"] - x["Neddutter"], x["Opdutter"], x["Neddutter"]))
86-
87-
if "!pomodoro" in message.content:
88-
await Pomodoro.startTimers(message)
6+
bot = commands.Bot(command_prefix='!')
897

90-
if "!time" in message.content:
91-
await message.channel.send('Remaining time: {}'.format(Pomodoro.calculateRemainingTime()))
8+
@bot.command(hidden=True)
9+
async def load(ctx, extension):
10+
bot.load_extension(f'cogs.{extension}')
11+
await ctx.message.delete()
9212

93-
if "!p" in message.content:
94-
await Player.play(message)
13+
@bot.command(hidden=True)
14+
async def unload(ctx, extension):
15+
bot.unload_extension(f'cogs.{extension}')
16+
await ctx.message.delete()
9517

96-
# Hidden easter egg for the boys
97-
if message.content == "!bot":
98-
await message.channel.send('Botten er så tæt på at være færdig :pinching_hand:')
18+
@bot.command(hidden=True)
19+
async def reload(ctx, extension):
20+
bot.unload_extension(f'cogs.{extension}')
21+
bot.load_extension(f'cogs.{extension}')
22+
await ctx.message.delete()
9923

100-
@client.event
24+
@bot.event
10125
async def on_ready():
102-
print(f'{client.user} has connected to Discord!')
26+
print(f'{bot.user} has connected to Discord!')
10327

104-
# Fix db
105-
for document in Db.mycol.find():
106-
print(document)
28+
for filename in os.listdir('./DiscordKarmaBot/cogs'):
29+
if filename.endswith('.py'):
30+
bot.load_extension(f'cogs.{filename[:-3]}')
10731

108-
client.run(os.getenv("TOKEN"))
32+
bot.run(os.getenv("TOKEN"))

0 commit comments

Comments
 (0)