Compare commits
1 Commits
release_br
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 63d4faab4f |
0
Jenkinsfile
vendored
Executable file → Normal file
0
Jenkinsfile
vendored
Executable file → Normal file
31
cogs/info.py
31
cogs/info.py
@@ -1,31 +0,0 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from mcstatus import MinecraftServer
|
||||
|
||||
|
||||
class ServerInfo(commands.Cog):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
|
||||
@commands.command(name="info")
|
||||
async def info(self, ctx):
|
||||
port = "25201"
|
||||
ip = "81.82.224.207"
|
||||
server = MinecraftServer.lookup(f"{ip}:{port}")
|
||||
# List of colours for the amount of servers that are online
|
||||
|
||||
embed = discord.Embed()
|
||||
embed.set_author(name="Info")
|
||||
embed.colour = discord.Colour.orange()
|
||||
embed.add_field(name="Ip", value=f"play.worldcraft.us", inline=False)
|
||||
embed.add_field(
|
||||
name="Dynmap", value=f"https://map.worldcraft.us/", inline=False)
|
||||
embed.add_field(
|
||||
name="Online", value=f"There are **{server.status().players.online}** players online!", inline=False)
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
|
||||
def setup(client):
|
||||
# client.add_cog(ServerInfo(client))
|
||||
pass
|
||||
@@ -31,25 +31,7 @@ class Leaderboards(commands.Cog):
|
||||
if column == "quizWins":
|
||||
top_players = []
|
||||
quizplayersdb = QuizPlayersDB()
|
||||
for player in quizplayersdb.get_top_players("wins"):
|
||||
discorduser = {}
|
||||
discorduser["playerName"] = deEmojify((await self.client.fetch_user(player["discordid"])).name).strip()
|
||||
discorduser["stat"] = player["stat"]
|
||||
top_players.append(discorduser)
|
||||
quizplayersdb.close()
|
||||
elif column == "max_streak":
|
||||
top_players = []
|
||||
quizplayersdb = QuizPlayersDB()
|
||||
for player in quizplayersdb.get_top_players("max_streak"):
|
||||
discorduser = {}
|
||||
discorduser["playerName"] = deEmojify((await self.client.fetch_user(player["discordid"])).name).strip()
|
||||
discorduser["stat"] = player["stat"]
|
||||
top_players.append(discorduser)
|
||||
quizplayersdb.close()
|
||||
elif column == "streak_count":
|
||||
top_players = []
|
||||
quizplayersdb = QuizPlayersDB()
|
||||
for player in quizplayersdb.get_top_players("streak_count"):
|
||||
for player in quizplayersdb.get_top_players():
|
||||
discorduser = {}
|
||||
discorduser["playerName"] = deEmojify((await self.client.fetch_user(player["discordid"])).name).strip()
|
||||
discorduser["stat"] = player["stat"]
|
||||
@@ -122,16 +104,6 @@ class Leaderboards(commands.Cog):
|
||||
embed = await self.create_leaderboard_embed("Quiz wins", "quizWins")
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@top.command(name="streak", case_insensitive=True)
|
||||
async def top_streak(self, ctx):
|
||||
embed = await self.create_leaderboard_embed("Longest streak", "max_streak")
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@top.command(name="streakcount", case_insensitive=True)
|
||||
async def top_streak_count(self, ctx):
|
||||
embed = await self.create_leaderboard_embed("Streak count", "streak_count")
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(Leaderboards(client))
|
||||
|
||||
73
cogs/quiz.py
73
cogs/quiz.py
@@ -8,13 +8,14 @@ from functions.timer import Timer
|
||||
from data.DatabaseConnection import *
|
||||
from functions import checks
|
||||
|
||||
|
||||
class QuizQuestions(commands.Cog):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
|
||||
@commands.group(name="questions",case_insensitive=True, invoke_without_command=True)
|
||||
@commands.group(name="questions", case_insensitive=True, invoke_without_command=True)
|
||||
@commands.check(checks.isModPlus)
|
||||
# /q&a add "What is ...." "Australia"
|
||||
# /q&a add "What is ...." "answer"
|
||||
async def questions(self, ctx, *args):
|
||||
pass
|
||||
|
||||
@@ -26,14 +27,14 @@ class QuizQuestions(commands.Cog):
|
||||
q_id = quizdb.add_question(q, a, reward)
|
||||
embed = discord.Embed()
|
||||
embed.colour = discord.Colour.green()
|
||||
embed.add_field(name="Success", value=f"Added question with {q_id}", inline=False)
|
||||
embed.add_field(
|
||||
name="Success", value=f"Added question with {q_id}", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
except:
|
||||
await ctx.send("Something went wrong")
|
||||
finally:
|
||||
quizdb.close()
|
||||
|
||||
|
||||
@questions.command(name="rm")
|
||||
@commands.check(checks.isModPlus)
|
||||
async def rm_question(self, ctx, id):
|
||||
@@ -42,7 +43,8 @@ class QuizQuestions(commands.Cog):
|
||||
quizdb.rm_question(id)
|
||||
embed = discord.Embed()
|
||||
embed.colour = discord.Colour.green()
|
||||
embed.add_field(name="Success", value=f"Question removed with id {id}", inline=False)
|
||||
embed.add_field(
|
||||
name="Success", value=f"Question removed with id {id}", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
except QuestionNotFound:
|
||||
await ctx.send("No question found with id " + str(id))
|
||||
@@ -60,7 +62,8 @@ class QuizQuestions(commands.Cog):
|
||||
if len(questions) == 0:
|
||||
embed = discord.Embed()
|
||||
embed.colour = discord.Colour.red()
|
||||
embed.add_field(name="Questions", value=f"No questions found", inline=False)
|
||||
embed.add_field(name="Questions",
|
||||
value=f"No questions found", inline=False)
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
else:
|
||||
@@ -68,16 +71,15 @@ class QuizQuestions(commands.Cog):
|
||||
embed.set_author(name="Questions")
|
||||
embed.colour = discord.Colour.orange()
|
||||
for q in questions:
|
||||
embed.add_field(name=f"id: {q[0]}", value=f"Question: '{q[1]}'\nAnswer: '{q[2]}'\nReward: {q[3]}\nUsed: {q[4]}", inline=False)
|
||||
embed.add_field(
|
||||
name=f"id: {q[0]}", value=f"Question: '{q[1]}'\nAnswer: '{q[2]}'\nReward: {q[3]}\nUsed: {q[4]}", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
except:
|
||||
await ctx.send("Something went wrong")
|
||||
finally:
|
||||
quizdb.close()
|
||||
|
||||
|
||||
|
||||
@commands.group(name="wordgame",case_insensitive=True, invoke_without_command=True)
|
||||
@commands.group(name="wordgame", case_insensitive=True, invoke_without_command=True)
|
||||
@commands.check(checks.isModPlus)
|
||||
# /q&a add "What is ...." "Australia"
|
||||
async def wordgame(self, ctx, *args):
|
||||
@@ -91,14 +93,14 @@ class QuizQuestions(commands.Cog):
|
||||
w_id = wordgamedb.add_word(w, reward)
|
||||
embed = discord.Embed()
|
||||
embed.colour = discord.Colour.green()
|
||||
embed.add_field(name="Success", value=f"Added word with {w_id}", inline=False)
|
||||
embed.add_field(
|
||||
name="Success", value=f"Added word with {w_id}", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
except:
|
||||
await ctx.send("Something went wrong")
|
||||
finally:
|
||||
wordgamedb.close()
|
||||
|
||||
|
||||
@wordgame.command(name="rm")
|
||||
@commands.check(checks.isModPlus)
|
||||
async def rm_word(self, ctx, id):
|
||||
@@ -107,7 +109,8 @@ class QuizQuestions(commands.Cog):
|
||||
wordgamedb.rm_word(id)
|
||||
embed = discord.Embed()
|
||||
embed.colour = discord.Colour.green()
|
||||
embed.add_field(name="Success", value=f"Question removed with id {id}", inline=False)
|
||||
embed.add_field(
|
||||
name="Success", value=f"Question removed with id {id}", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
except QuestionNotFound:
|
||||
await ctx.send("No question found with id " + str(id))
|
||||
@@ -125,7 +128,8 @@ class QuizQuestions(commands.Cog):
|
||||
if len(words) == 0:
|
||||
embed = discord.Embed()
|
||||
embed.colour = discord.Colour.red()
|
||||
embed.add_field(name="Words", value=f"No words found", inline=False)
|
||||
embed.add_field(
|
||||
name="Words", value=f"No words found", inline=False)
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
else:
|
||||
@@ -133,23 +137,24 @@ class QuizQuestions(commands.Cog):
|
||||
embed.set_author(name="Words")
|
||||
embed.colour = discord.Colour.orange()
|
||||
for w in words:
|
||||
embed.add_field(name=f"id: {w['id']}", value=f"Word: '{w['word']}'\nReward: {w['reward']}\nUsed: {w['asked']}", inline=False)
|
||||
embed.add_field(
|
||||
name=f"id: {w['id']}", value=f"Word: '{w['word']}'\nReward: {w['reward']}\nUsed: {w['asked']}", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
except:
|
||||
await ctx.send("Something went wrong")
|
||||
finally:
|
||||
wordgamedb.close()
|
||||
|
||||
|
||||
class Quiz(commands.Cog):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
#self.interval = (1, 4)
|
||||
self.interval = (5*60, 15*60)
|
||||
self.interval = (5*60, 20*60)
|
||||
self.auto = False
|
||||
self.timeout = 10*60
|
||||
|
||||
|
||||
@commands.group(name="quiz",case_insensitive=True, invoke_without_command=True)
|
||||
@commands.group(name="quiz", case_insensitive=True, invoke_without_command=True)
|
||||
@commands.check(checks.isModPlus)
|
||||
async def quiz(self, ctx, f, *args):
|
||||
pass
|
||||
@@ -165,7 +170,6 @@ class Quiz(commands.Cog):
|
||||
async def auto_quiz(self, ctx):
|
||||
self.auto = False
|
||||
|
||||
|
||||
async def start_auto_quiz(self):
|
||||
while self.auto:
|
||||
await asyncio.sleep(random.randint(self.interval[0], self.interval[1]))
|
||||
@@ -187,29 +191,38 @@ class Quiz(commands.Cog):
|
||||
embed.colour = discord.Colour.orange()
|
||||
|
||||
embed.add_field(name="Question:", value=f"{question}", inline=False)
|
||||
embed.add_field(name="Reward:", value=f"${reward} x streak in game", inline=False)
|
||||
embed.add_field(name="End:", value=f"The quiz will end in 10 minutes!", inline=False)
|
||||
embed.add_field(
|
||||
name="Reward:", value=f"${reward} x streak in game", inline=False)
|
||||
embed.add_field(
|
||||
name="End:", value=f"The quiz will end in 10 minutes!", inline=False)
|
||||
return embed
|
||||
|
||||
def create_answer_embed(self, question, answer, reward, streak=-1, author=None, linked=False, correct=False):
|
||||
embed = discord.Embed()
|
||||
|
||||
embed.add_field(name="Question:", value=f"{question}", inline=False)
|
||||
embed.add_field(name="Reward:", value=f"${reward} in game", inline=False)
|
||||
embed.add_field(
|
||||
name="Reward:", value=f"${reward} in game", inline=False)
|
||||
embed.add_field(name="Answer:", value=f"{answer}", inline=False)
|
||||
|
||||
if correct:
|
||||
embed.colour = discord.Colour.green()
|
||||
if linked:
|
||||
embed.add_field(name="Winner:", value=f"{author.mention} 🎉🎉", inline=False)
|
||||
embed.add_field(name="Claim:", value=f"Claim your reward in Minecraft by using /redeem")
|
||||
embed.add_field(
|
||||
name="Winner:", value=f"{author.mention} 🎉🎉", inline=False)
|
||||
embed.add_field(
|
||||
name="Claim:", value=f"Claim your reward in Minecraft by using /redeem")
|
||||
if streak > 1:
|
||||
embed.add_field(name="Streak:", value=f"{author.mention} has a streak going of {streak}", inline=False)
|
||||
embed.add_field(
|
||||
name="Streak:", value=f"{author.mention} has a streak going of {streak}", inline=False)
|
||||
else:
|
||||
embed.add_field(name="Winner:", value=f"{author.mention} 🎉🎉", inline=False)
|
||||
embed.add_field(name="Claim:", value=f"1. Link your account by using /link <MinecraftName> \n2. Claim your reward in Minecraft by using /redeem", inline=False)
|
||||
embed.add_field(
|
||||
name="Winner:", value=f"{author.mention} 🎉🎉", inline=False)
|
||||
embed.add_field(
|
||||
name="Claim:", value=f"1. Link your account by using /link <MinecraftName> \n2. Claim your reward in Minecraft by using /redeem", inline=False)
|
||||
if streak > 1:
|
||||
embed.add_field(name="Streak:", value=f"{author.mention} has a streak going of {streak}", inline=False)
|
||||
embed.add_field(
|
||||
name="Streak:", value=f"{author.mention} has a streak going of {streak}", inline=False)
|
||||
else:
|
||||
embed.colour = discord.Colour.red()
|
||||
return embed
|
||||
@@ -271,7 +284,6 @@ class Quiz(commands.Cog):
|
||||
await channel.send("Nobody found the correct answer!")
|
||||
await channel.send(embed=self.create_answer_embed(f"Find the word from: {shaken_word}", word["word"], word["reward"]))
|
||||
|
||||
|
||||
def shake_word(self, word):
|
||||
word_list = list(word)
|
||||
random.shuffle(word_list)
|
||||
@@ -312,7 +324,8 @@ class Quiz(commands.Cog):
|
||||
quiz_players_db.reset_streak(previousstreak["discordid"])
|
||||
|
||||
if previousstreak is not None and str(previousstreak["discordid"]) == str(discordid):
|
||||
quiz_players_db.player_won(discordid, reward * (previousstreak["cur_streak"] + 1))
|
||||
quiz_players_db.player_won(
|
||||
discordid, reward * (previousstreak["cur_streak"] + 1))
|
||||
else:
|
||||
quiz_players_db.player_won(discordid, reward)
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from functions.checks import *
|
||||
import requests
|
||||
from io import BytesIO
|
||||
|
||||
class SuggestionMessage(commands.Cog):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
self.channels = ["740308147385663518", "761327043894968330"]
|
||||
|
||||
@commands.command(name="suggestion")
|
||||
async def suggestion(self, ctx, *, arg):
|
||||
if str(ctx.channel.id) in self.channels or isModPlus(ctx):
|
||||
embed = discord.Embed()
|
||||
embed.set_author(name=ctx.author.display_name)
|
||||
embed.colour = discord.Colour.orange()
|
||||
embed.description = f"{arg}"
|
||||
if len(ctx.message.attachments) > 0:
|
||||
attachment_url = ctx.message.attachments[0].url
|
||||
embed.set_image(url="attachment://image.png")
|
||||
message = await ctx.send(embed=embed, file=self.get_image_from_url(attachment_url))
|
||||
else:
|
||||
message = await ctx.send(embed=embed)
|
||||
await ctx.message.delete()
|
||||
await message.add_reaction("✅")
|
||||
await message.add_reaction("❌")
|
||||
|
||||
def get_image_from_url(self, url):
|
||||
res = requests.get(url)
|
||||
arr = BytesIO(res.content)
|
||||
arr.seek(0)
|
||||
file=discord.File(fp=arr, filename='image.png')
|
||||
return file
|
||||
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(SuggestionMessage(client))
|
||||
@@ -76,7 +76,7 @@ class QuizPlayersDB:
|
||||
sql = f"UPDATE {self.tablename} SET wins = wins + 1, rewards = rewards + {str(reward)}, toclaim = toclaim + {str(reward)} WHERE discordid = {str(discordid)}"
|
||||
cursor.execute(sql)
|
||||
else:
|
||||
sql = f"INSERT INTO {self.tablename} (discordid, wins, rewards, toclaim, cur_streak, max_streak, streak_count) VALUES ({str(discordid)}, 1, {reward}, {reward}, 0, 0, 0)"
|
||||
sql = f"INSERT INTO {self.tablename} (discordid, wins, rewards, toclaim) VALUES ({str(discordid)}, 1, {reward}, {reward}, 0, 0)"
|
||||
cursor.execute(sql)
|
||||
|
||||
self.increment_cur_streak(discordid)
|
||||
@@ -98,9 +98,9 @@ class QuizPlayersDB:
|
||||
cursor.execute(sql)
|
||||
self.discorddbconn.get_db().commit()
|
||||
|
||||
def get_top_players(self, column, limit = 20):
|
||||
def get_top_players(self, limit = 20):
|
||||
cursor = self.discorddbconn.get_cursor(dictionary=True)
|
||||
sql = f"SELECT discordid, {column} as stat FROM {self.tablename} ORDER BY {column} DESC LIMIT {str(limit)}"
|
||||
sql = f"SELECT discordid, wins as stat FROM {self.tablename} ORDER BY wins DESC LIMIT {str(limit)}"
|
||||
cursor.execute(sql)
|
||||
return list(cursor.fetchall())
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
discord.py==1.5.0
|
||||
mcstatus==4.0.0
|
||||
mysql-connector-python==8.0.21
|
||||
requests==2.25.0
|
||||
|
||||
Reference in New Issue
Block a user