Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
552f14b
Delete Discord Bot - Music Player directory
angwarrenn Jul 14, 2022
3045b31
Delete #Discord Bot Basic.py
angwarrenn Jul 14, 2022
3af94a9
Delete README.md
angwarrenn Jul 14, 2022
541e4a1
init
angwarrenn Jul 14, 2022
08ee4fd
v2 bot alive
angwarrenn Jul 14, 2022
66340a4
added README
Jul 14, 2022
8a23d46
slash commands
angwarrenn Jul 20, 2022
3b5eaf7
Delete __pycache__ directory
angwarrenn Jul 20, 2022
161dc9f
updated
angwarrenn Jul 21, 2022
7a4fc4d
clean up
angwarrenn Jul 21, 2022
5a9e924
Merge branch 'tictactoe' of https://github.com/HackMelbourne/Decoded-…
angwarrenn Jul 21, 2022
626c122
updated
angwarrenn Jul 21, 2022
4a238b2
clean up
angwarrenn Jul 21, 2022
5736a24
Create w3-participant-workshop
Jerry2108 Jul 27, 2022
dc6744f
Update README.md
Jerry2108 Jul 27, 2022
529a986
Update README.md
Jerry2108 Jul 27, 2022
2e36dbd
Update README.md
Jerry2108 Jul 27, 2022
b61bdbd
Update README.md
Jerry2108 Jul 27, 2022
0d78ee4
Update README.md
Jerry2108 Jul 27, 2022
7188dfe
update
Jul 27, 2022
8cfda93
Add poll system
nonamegohst Jul 28, 2022
8679d44
Add env file
nonamegohst Jul 28, 2022
7ead406
Remove swear word thing
Ry-DS Jul 30, 2022
541f885
rename music bot
Ry-DS Jul 30, 2022
6ff7ae0
Merge branch 'main' into music-bot
Ry-DS Jul 30, 2022
e2c0189
Merge branch 'main' into music-bot
Ry-DS Jul 30, 2022
148fea2
COG bot
Ry-DS Jul 30, 2022
cf4e5b1
Say if you're not in voice
Ry-DS Jul 30, 2022
d029d2a
init
angwarrenn Aug 2, 2022
6b69f3e
Update README.md
Jerry2108 Aug 3, 2022
554135f
Update main.py
Jerry2108 Aug 3, 2022
425905c
Update README.md
Jerry2108 Aug 3, 2022
06f611d
Update README.md
Jerry2108 Aug 3, 2022
e349140
Update main.py
Jerry2108 Aug 3, 2022
700f358
Update README.md
Jerry2108 Aug 3, 2022
450c4c5
Update README.md
Jerry2108 Aug 3, 2022
b349fb7
Update README.md
Jerry2108 Aug 3, 2022
b8a075e
Update README.md
Jerry2108 Aug 3, 2022
cac907a
Update README.md
Jerry2108 Aug 3, 2022
b2917d7
Update README.md
Jerry2108 Aug 3, 2022
03d36e2
Update README.md
Jerry2108 Aug 3, 2022
071b122
Update README.md
Jerry2108 Aug 3, 2022
8c2f30b
Update README.md
Jerry2108 Aug 3, 2022
935a793
Update README.md
Jerry2108 Aug 3, 2022
61a1e03
Update w5-participant-workbook.md
IQ-TREX Aug 5, 2022
325ebb6
workbook
angwarrenn Aug 6, 2022
bedcb7b
[I] - initial commit
thien-an-ly Aug 10, 2022
f93d6ac
Update README.md
Jerry2108 Aug 10, 2022
7b2c4b3
Update README.md
Jerry2108 Aug 10, 2022
3541670
Update README.md
Jerry2108 Aug 10, 2022
f45905b
Update README.md
Jerry2108 Aug 10, 2022
95c6236
Update README.md
Jerry2108 Aug 10, 2022
e25dc4d
[R] - refactor to use @commands
thien-an-ly Aug 13, 2022
f9a647f
[E] - edit Minh's part
thien-an-ly Aug 14, 2022
2a1c545
[E] - edit, cut out repeated part & reformat structure
thien-an-ly Aug 14, 2022
da502d7
Fix week
Ry-DS Aug 15, 2022
8af1ed6
move to w2
Ry-DS Aug 15, 2022
9b37849
Merge and find a way to integrate with main
Ry-DS Aug 15, 2022
4c66b23
Merge branch 'main' into music-bot
Ry-DS Aug 15, 2022
0680959
Move stuff
Ry-DS Aug 15, 2022
f019fa1
Spelling mistake
Ry-DS Aug 15, 2022
8cb7021
Music bot now works with cogs
Ry-DS Aug 15, 2022
3bf509f
Merge remote-tracking branch 'refs/remotes/origin/main'
Ry-DS Aug 15, 2022
142a241
put readme back
Ry-DS Aug 15, 2022
bb669a3
this needs to be fixed
Ry-DS Aug 15, 2022
083f87e
Merge branch 'main'
Ry-DS Aug 15, 2022
dbb4c10
Make cogs work
Ry-DS Aug 15, 2022
eddf1b3
Delete redundant notebook
Ry-DS Aug 15, 2022
050b967
Bot works so well now
Ry-DS Aug 15, 2022
1115bcb
fix stop command
Ry-DS Aug 15, 2022
936cd39
cleanup and force jdk 13
Ry-DS Aug 16, 2022
389f2b4
Update README.md
Jerry2108 Aug 16, 2022
6899b93
Update README.md
Jerry2108 Aug 16, 2022
020d10c
Update README.md
Jerry2108 Aug 16, 2022
05b1556
Update README.md
Jerry2108 Aug 17, 2022
812bea7
Update README.md
Jerry2108 Aug 17, 2022
372e477
Update README.md
Jerry2108 Aug 17, 2022
ebe3a59
Update README.md
Jerry2108 Aug 17, 2022
012fbdf
Update README.md
Jerry2108 Aug 17, 2022
a4bf98f
Update README.md
Jerry2108 Aug 17, 2022
012b682
Update README.md
Jerry2108 Aug 17, 2022
03ec0a3
Update README.md
IQ-TREX Aug 17, 2022
24c005e
Update README.md
IQ-TREX Aug 17, 2022
6ffe554
Update README.md
Jerry2108 Aug 17, 2022
63fc659
Update README.md
Jerry2108 Aug 17, 2022
7415bf7
Update README.md
Jerry2108 Aug 17, 2022
4223d2b
Update README.md
Jerry2108 Aug 17, 2022
1dd83dd
Update README.md
Jerry2108 Aug 17, 2022
f195c0c
Update README.md
Jerry2108 Aug 17, 2022
a851bd3
Update README.md
Jerry2108 Aug 17, 2022
933a657
Update README.md
Jerry2108 Aug 17, 2022
d8b48b4
Create oldReadme.md
Jerry2108 Aug 17, 2022
4799a85
progress on musicbot
Ry-DS Aug 17, 2022
27efd8b
Merge remote-tracking branch 'origin/music-bot' into music-bot
Ry-DS Aug 17, 2022
0e1771e
make things work again
Ry-DS Aug 17, 2022
798672f
fixed refactoring error
angwarrenn Aug 17, 2022
29100ef
fixed refactoring error
angwarrenn Aug 17, 2022
aa8238a
Make thing work with main2.py
Ry-DS Aug 17, 2022
3c55de3
fix env
Ry-DS Aug 17, 2022
c8b62bc
make meme bot a cog
Ry-DS Aug 18, 2022
5333075
Merge branch 'tictactoe' into combined
Ry-DS Aug 18, 2022
4c777b1
Merge branch 'music-bot' into combined
Ry-DS Aug 18, 2022
316b70b
better command names
Ry-DS Aug 18, 2022
34a14da
Merge branch 'meme_bot_cog' into combined
Ry-DS Aug 18, 2022
25e2e94
Merge branch 'poll_system' into combined
Ry-DS Aug 18, 2022
78b0f9e
ignore
Ry-DS Aug 18, 2022
3f1f16a
cleanup combined
Ry-DS Aug 18, 2022
2a6687e
Update poll.py
Jerry2108 Aug 18, 2022
0ee5a33
Update poll.py
Jerry2108 Aug 18, 2022
8f8d26f
Update README.md
Jerry2108 Aug 18, 2022
a2e341a
Update README.md
Jerry2108 Aug 18, 2022
6916acf
Update README.md
Jerry2108 Aug 18, 2022
d68279c
Update README.md
Jerry2108 Aug 18, 2022
49c011d
Update README.md
Jerry2108 Aug 18, 2022
f720961
Update README.md
Jerry2108 Aug 18, 2022
fbbc105
Update README.md
Jerry2108 Aug 18, 2022
0021dc3
Update README.md
Jerry2108 Aug 18, 2022
90f7191
Update README.md
Jerry2108 Aug 18, 2022
935a1ff
Update README.md
Jerry2108 Aug 18, 2022
0abed1b
Update README.md
Jerry2108 Aug 18, 2022
a9e68f8
Update README.md
Jerry2108 Aug 18, 2022
1c3e32b
Update README.md
Jerry2108 Aug 18, 2022
c6a124d
Update README.md
Jerry2108 Aug 18, 2022
938f03c
Update README.md
Jerry2108 Aug 18, 2022
d9ba01a
Update README.md
Jerry2108 Aug 18, 2022
2e5ab7b
Merge remote-tracking branch 'origin/poll_system' into combined
Ry-DS Aug 19, 2022
bf75fe9
fix poll bot
Ry-DS Aug 19, 2022
8a52754
add wavelink + others
Ry-DS Aug 22, 2022
4ed1eb0
Add emoji dep plus others
Ry-DS Aug 22, 2022
ad5c3c1
fix message
Ry-DS Aug 22, 2022
8a04bd1
actually fix issue
Ry-DS Aug 22, 2022
740b18a
Add check for avatar before setting author
Ry-DS Aug 24, 2022
157f874
Merge branch 'main' into combined
Ry-DS Aug 26, 2022
c2203e6
Merge remote-tracking branch 'origin/combined' into combined
Ry-DS Aug 26, 2022
0970f72
Merge branch 'main' into combined
Ry-DS Aug 26, 2022
eb82205
Merge branch 'main' into combined
Ry-DS Aug 29, 2022
dbfbc0f
Merge branch 'main' into combined
Ry-DS Sep 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@

*.pyc
/logs/


__pycache__/

jdk-13.0.2/
.DS_Store
50 changes: 50 additions & 0 deletions EmojiCollection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import emoji
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait


class EmojiCollection():
def __init__(self):

options = Options()
# TODO this can't be OS specific
# options.binary_location = "/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta"
options.binary_location = "C:\Program Files\Google\Chrome\Application\chrome.exe"

self.driver = webdriver.Chrome(options=options)
self.driver.get("https://emojipedia.org")
# accepts cookies
acceptCookies = WebDriverWait(
self.driver,
30).until(EC.presence_of_element_located((By.ID, "onetrust-accept-btn-handler"))).click()

def searchEngineReturned(self):
#click onto the link of the first emoji
clickFirstEmoji = WebDriverWait(self.driver, 30).until(
EC.element_to_be_clickable((By.XPATH, "/html/body/div[@class='container']/div[@class='content']/ol/*[1]/h2/a"))).click()
def getEmoji(self):
try:
nameOfEmoji = WebDriverWait(self.driver, 10).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "span.shortcode"))).text
return emoji.emojize(nameOfEmoji)
except selenium.common.exceptions.TimeOutException:
tmp = emoji.emojize(":red_heart:")
return tmp
#enter the requested emoji to the search engine
def search(self, emoji):
#type a key word to the search engine
element = self.driver.find_element(By.ID, "id_q")
element.send_keys(emoji)
#the search engine starts searching
element.send_keys(Keys.RETURN)
self.searchEngineReturned()
return self.getEmoji()

def quit(self):
self.driver.quit()

Binary file added Lavalink.jar
Binary file not shown.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<h1 align="center">DecodED 3</h1>

> 👋 Hello and welcome to DecodED 3! Over the next 5 weeks, we will be creating a discord bot with [Discord.py](https://discordpy.readthedocs.io/en/stable/index.html)
> 👋 Hello and welcome to DecodED 3! Over the next 5 weeks, we will be creating a discord bot
> with [Discord.py](https://discordpy.readthedocs.io/en/stable/index.html)

---

Expand All @@ -25,9 +26,8 @@
## About DecodED

* DecodED is a series of workshops run every year by HackMelbourne to help students/teach students with introductory
programming background to create some cool things with code. In past years, we created full-stack websites and a Space Invaders game. This year, we will be creating a Discord bot!
programming background tocreate some cool things with code. In past years, we created full-stack websites and a Space Invaders game. This year, we will be creating a Discord bot!
* We are also trying a new teaching style this year so let us know if you like it!

### Dates

Get the latest details on [Notion](https://uneven-boa-710.notion.site/DecodED-3-3336c8bbd49a4df6a00b8b34af1980c6) (the below table may be outdated)
Expand All @@ -41,14 +41,17 @@ TicTacToe bot | Alan Gilbert 103 and Zoom | Warren, Daniel | 2pm, Wednesday 14th
Music bot | Alan Gilbert 121 (Theatre) and Zoom | Aryan, Ryan | Wednesday 21st September

### Zoom Link: https://unimelb.zoom.us/j/88528442813?pwd=WlYrQ3pHcm5xMXpGQkZZSllZZTNvQT09

Password: 323737

## About this repository

* This repository contains:
* Participant Workbook
* each workbook is made up of multiple Parts which are then made up of multiple **✅ Tasks** that the participant
should complete, with **🧩 Hints** that help guide them in completing the Task, and **💡 Extensions** that are
optional tasks that can be done if the participant has completed the Task ahead of schedule

* Workshop Recordings
* Code for the Discord Bot being created

Expand All @@ -66,6 +69,7 @@ Password: 323737

> Who doesn’t love a good meme? Join us and create the functionality to meme on your friends so hard that they wished
> they had their own meme bot.

>
> Hosted by Aly and Minh

Expand Down
13 changes: 13 additions & 0 deletions Server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import http.server
import socketserver
import os
from dotenv import load_dotenv

load_dotenv()
def runServer():
Handler = http.server.SimpleHTTPRequestHandler
port = os.environ.get('PORT')
with socketserver.TCPServer(("", int(port)), Handler) as httpd:
print(f'serving at port {port}')
httpd.serve_forever()

49 changes: 49 additions & 0 deletions application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
server: # REST and WS server
port: 2333
address: localhost
lavalink:
server:
password: "youshallnotpass"
sources:
youtube: true
bandcamp: true
soundcloud: true
twitch: true
vimeo: true
http: true
local: false
bufferDurationMs: 400 # The duration of the NAS buffer. Higher values fare better against longer GC pauses
frameBufferDurationMs: 5000 # How many milliseconds of audio to keep buffered
youtubePlaylistLoadLimit: 6 # Number of pages at 100 each
playerUpdateInterval: 5 # How frequently to send player updates to clients, in seconds
youtubeSearchEnabled: true
soundcloudSearchEnabled: true
gc-warnings: true
#ratelimit:
#ipBlocks: ["1.0.0.0/8", "..."] # list of ip blocks
#excludedIps: ["...", "..."] # ips which should be explicit excluded from usage by lavalink
#strategy: "RotateOnBan" # RotateOnBan | LoadBalance | NanoSwitch | RotatingNanoSwitch
#searchTriggersFail: true # Whether a search 429 should trigger marking the ip as failing
#retryLimit: -1 # -1 = use default lavaplayer value | 0 = infinity | >0 = retry will happen this numbers times

metrics:
prometheus:
enabled: false
endpoint: /metrics

sentry:
dsn: ""
environment: ""
# tags:
# some_key: some_value
# another_key: another_value

logging:
file:
max-history: 30
max-size: 1GB
path: ./logs/

level:
root: INFO
lavalink: INFO
35 changes: 35 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import json
import os

import discord
from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv("TOKEN")
GUILDS = os.getenv("GUILDS")
GUILDS = json.loads(GUILDS)
GUILDS = [discord.Object(id=guild) for guild in GUILDS]


class Bot(commands.Bot):
def __init__(self):
super().__init__(command_prefix="!",
intents=discord.Intents.all())
self.GUILDS = GUILDS
self.TOKEN = TOKEN

async def setup_hook(self):
await self.load_extension(f"cogs.tictactoe")
for guild in self.GUILDS:
await self.tree.sync(guild=guild)

async def on_ready(self):
print("ready...")


bot = Bot()
bot.run(bot.TOKEN)

if __name__ == '__main__':
pass
23 changes: 23 additions & 0 deletions chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility
np.random.seed(19680801)


plt.rcdefaults()
fig, ax = plt.subplots()
# Example data
people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim')
y_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))
error = np.random.rand(len(people))

ax.barh(y_pos, performance, xerr=error, align='center')
ax.set_yticks(y_pos, labels=people)
ax.invert_yaxis() # labels read top-to-bottom
ax.set_xlabel('Performance')
ax.set_title('How fast do you want to go today?')


plt.savefig('chart.png')
152 changes: 152 additions & 0 deletions cogs/meme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import json
import os

import requests
from discord.ext import commands
from dotenv import load_dotenv
from pymongo import MongoClient
from requests.exceptions import HTTPError
from schema import Schema, SchemaError, And, Regex

load_dotenv()

TOKEN = os.getenv('TOKEN')
COMMAND = os.getenv('DISCORD_COMMAND_ROOT')
BOTNAME = os.getenv('BOT_NAME')
API_ROOT = os.getenv('MEME_API_ROOT')
MONGODB_URI = os.getenv('MONGODB_URI')
DB = os.getenv('DB')
COLLECTION = os.getenv('COLLECTION')

collection = MongoClient(MONGODB_URI)[DB][COLLECTION]


# all commands that this bot will respond to will begin with ";;bot_name"
# bot = commands.Bot(command_prefix=COMMAND + BOTNAME, strip_after_prefix=True, intents=discord.Intents.all())

def get_random_memes(count):
try:
response = requests.get(f"{API_ROOT}{count}")
except HTTPError as error:
raise error
json_data = json.loads(response.text)
return json_data


def get_random_meme_from_subreddits(subReddit, count):
try:
response = requests.get(f"{API_ROOT}{subReddit}/{count}")
except HTTPError as error:
raise error
if (response.status_code == 404 or response.status_code == 400):
raise HTTPError(response.text)
json_data = json.loads(response.text)
return json_data


def check_link_die(link):
try:
response = requests.get(link)
except:
return False
if (response.status_code == 404):
return False
return True


meme_schema = Schema({
"name": str,
"url": And(str, Regex("^(https:\/\/i.redd.it\/)\w+\.\w{3}$"))})


class Meme(commands.Cog):
def __init__(self, bot):
self.bot = bot

@commands.command()
async def meme(self, ctx, *args):
# ;;random
if (len(args) == 0):
random_meme = get_random_memes(1)['memes'][0]
while (check_link_die(random_meme['url']) == False):
random_meme = get_random_memes(1)['memes'][0]
await ctx.send(random_meme['url'])

# ;;random 5
if (len(args) > 0):
try:
random_memes = get_random_memes(int(args[0]))['memes']
except:
await ctx.send("Unrecognized command. Pretty sure that wasn't a number :)")
pass
random_memes_image_link = [e['url'] for e in random_memes]
for link in random_memes_image_link:
if (check_link_die(link) == False):
continue
else:
await ctx.send(link)
pass

@commands.command()
async def meme_subreddit(self, ctx, arg1):
subreddit = arg1
try:
random_meme = get_random_meme_from_subreddits(subreddit, 1)
random_meme_subreddit = random_meme['memes'][0]
while (check_link_die(random_meme_subreddit['url']) == False):
random_meme = get_random_meme_from_subreddits(subreddit, 1)
random_meme_subreddit = random_meme['memes'][0]
await ctx.send(random_meme_subreddit['url'])
except HTTPError as err:
await ctx.send('Subreddit not found')
pass
pass

@commands.command()
async def save_meme(self, ctx, arg1):
try:
response = await ctx.channel.fetch_message(ctx.message.reference.message_id)
meme_url = response.content
except print(0):
await ctx.send("You forgot to reply to a meme, or the meme you replied to wasn't saved in the right format")
pass
saved_name = arg1
saved_meme = {
"name": saved_name,
"url": meme_url,
}
try:
meme_schema.validate(saved_meme)
except SchemaError as err:
await ctx.send(err)
pass
collection.insert_one(saved_meme)
await ctx.send("Saved to database!")
pass

@commands.command()
async def load_meme(self, ctx, arg1):
lookup_name = arg1
try:
found_meme = collection.find_one({"name": lookup_name})
await ctx.send(found_meme["url"])
except TypeError:
await ctx.send("Meme not found in database!")
pass
pass

@commands.command()
async def delete_meme(self, ctx, arg1):
lookup_name = arg1
try:
found_meme = collection.find_one({"name": lookup_name})
except TypeError:
await ctx.send("Meme not found in database!")
pass
collection.delete_one(found_meme)
await ctx.send("Meme was deleted from database!")
pass


async def setup(bot):
await bot.add_cog(Meme(bot))
Loading