Compare commits
6 Commits
tests
...
release_br
| Author | SHA1 | Date | |
|---|---|---|---|
| f5010a9a51 | |||
| b59f122957 | |||
| d3f59679b0 | |||
| bed50fd252 | |||
| 41ff0e87cf | |||
| c2274b350e |
0
Jenkinsfile
vendored
Normal file → Executable file
0
Jenkinsfile
vendored
Normal file → Executable file
32
bot.py
32
bot.py
@@ -1,11 +1,27 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import sys
|
||||
from discord.ext import commands
|
||||
import os
|
||||
import yaml
|
||||
from bots.discordbot import DiscordBot
|
||||
|
||||
if __name__ == "__main__":
|
||||
bot = DiscordBot(sys.argv[1])
|
||||
bot.run()
|
||||
class DiscordBot:
|
||||
def __init__(self, config):
|
||||
|
||||
prefixes = ["/"]
|
||||
|
||||
self.client = commands.Bot(command_prefix=prefixes, case_insensitive=True)
|
||||
self.client.prefixes = prefixes
|
||||
|
||||
# Load this cog first so the other cogs can use properties initialized here
|
||||
self.client.load_extension("cogs.events")
|
||||
|
||||
for file in os.listdir("./cogs"):
|
||||
if file.endswith(".py") and not (file.startswith(("events",))):
|
||||
self.client.load_extension(f"cogs.{file[:-3]}")
|
||||
|
||||
def run(self):
|
||||
self.client.run("NzYwNTI5NDY2MDI3MDE2MjUy.X3NYQg.Nz3bwxgltlayMStfT7F-OCbx9pE")
|
||||
|
||||
def get_client(self):
|
||||
return self.client
|
||||
|
||||
|
||||
bot = DiscordBot(None)
|
||||
bot.run()
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import sys
|
||||
from discord.ext import commands
|
||||
import os
|
||||
import yaml
|
||||
|
||||
class DiscordBot:
|
||||
def __init__(self, config):
|
||||
print("jajajah")
|
||||
self.constants = ["token"]
|
||||
self.modules = {"quiz": "quiz"}
|
||||
prefixes = ["/"]
|
||||
|
||||
self.client = commands.Bot(command_prefix=prefixes, case_insensitive=True)
|
||||
self.client.prefixes = prefixes
|
||||
self.load_config(config)
|
||||
# Load this cog first so the other cogs can use properties initialized here
|
||||
self.client.load_extension("cogs.events")
|
||||
|
||||
# for file in os.listdir("./cogs"):
|
||||
# if file.endswith(".py") and not (file.startswith(("events",))):
|
||||
# self.client.load_extension(f"cogs.{file[:-3]}")
|
||||
|
||||
def run(self):
|
||||
if "token" in self.client.config.keys():
|
||||
print(self.client.config["token"])
|
||||
self.client.run(self.client.config["token"])
|
||||
|
||||
def get_client(self):
|
||||
return self.client
|
||||
|
||||
def load_config(self, config):
|
||||
with open(config, 'r') as file:
|
||||
try:
|
||||
self.client.config = yaml.safe_load(file)
|
||||
for cog in self.client.config:
|
||||
if cog not in self.constants and self.loaded_cog(cog):
|
||||
print(f"Loaded cog {cog}")
|
||||
except yaml.YAMLError as exc:
|
||||
print(exc)
|
||||
|
||||
def loaded_cog(self, module):
|
||||
if os.path.isfile(f"/cogs/{self.modules[module]}.py"):
|
||||
self.client.load_extension(f"cogs.{self.modules[module]}")
|
||||
return True
|
||||
return False
|
||||
31
cogs/info.py
Normal file
31
cogs/info.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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,7 +31,25 @@ class Leaderboards(commands.Cog):
|
||||
if column == "quizWins":
|
||||
top_players = []
|
||||
quizplayersdb = QuizPlayersDB()
|
||||
for player in quizplayersdb.get_top_players():
|
||||
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"):
|
||||
discorduser = {}
|
||||
discorduser["playerName"] = deEmojify((await self.client.fetch_user(player["discordid"])).name).strip()
|
||||
discorduser["stat"] = player["stat"]
|
||||
@@ -104,6 +122,16 @@ 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))
|
||||
|
||||
14
cogs/quiz.py
14
cogs/quiz.py
@@ -1,5 +1,6 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from data import constants
|
||||
import asyncio
|
||||
import threading
|
||||
import random
|
||||
@@ -142,10 +143,11 @@ class QuizQuestions(commands.Cog):
|
||||
class Quiz(commands.Cog):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
#self.interval = (1, 4)
|
||||
self.interval = (5*60, 15*60)
|
||||
self.auto = False
|
||||
self.quiz_config = self.client.config["quiz"]
|
||||
self.interval = (int(self.quiz_config["interval_start"]) * 60, int(self.quiz_config["interval_end"]) * 60)
|
||||
self.timeout = int(self.quiz_config["timeout"])*60
|
||||
self.timeout = 10*60
|
||||
|
||||
|
||||
@commands.group(name="quiz",case_insensitive=True, invoke_without_command=True)
|
||||
@commands.check(checks.isModPlus)
|
||||
@@ -216,7 +218,7 @@ class Quiz(commands.Cog):
|
||||
ranges = {10: 50, 25: 75, 50: 100, 75: 125, 100: 150}
|
||||
range = random.choice(list(ranges))
|
||||
random_number = random.randint(1, range)
|
||||
channel = self.client.get_channel(self.quiz_config["channel"])
|
||||
channel = self.client.get_channel(constants.QuizChannelID)
|
||||
await channel.send(embed=self.create_question_embed(f"Guess the number from 1 to {range}", ranges[range]))
|
||||
await channel.edit(slowmode_delay=1)
|
||||
try:
|
||||
@@ -236,7 +238,7 @@ class Quiz(commands.Cog):
|
||||
async def ask_question(self):
|
||||
question = self.get_random_question()
|
||||
self.increment_asked_count(question[0])
|
||||
channel = self.client.get_channel(self.quiz_config["channel"])
|
||||
channel = self.client.get_channel(constants.QuizChannelID)
|
||||
await channel.send(embed=self.create_question_embed(question[1], question[3]))
|
||||
try:
|
||||
message = await self.client.wait_for("message", check=lambda message: message.content.lower() == question[2].lower(), timeout=self.timeout)
|
||||
@@ -253,7 +255,7 @@ class Quiz(commands.Cog):
|
||||
async def start_word_game(self):
|
||||
word = self.get_random_word()
|
||||
self.increment_asked_word(int(word["id"]))
|
||||
channel = self.client.get_channel(self.quiz_config["channel"])
|
||||
channel = self.client.get_channel(constants.QuizChannelID)
|
||||
shaken_word = self.shake_word(word["word"].lower())
|
||||
await channel.send(embed=self.create_question_embed(f"Find the word from: {shaken_word}", word['reward']))
|
||||
try:
|
||||
|
||||
38
cogs/suggestion.py
Normal file
38
cogs/suggestion.py
Normal file
@@ -0,0 +1,38 @@
|
||||
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))
|
||||
12
config.yaml
12
config.yaml
@@ -1,12 +0,0 @@
|
||||
quiz:
|
||||
channel: 779084465426399272
|
||||
# question interval between questions in minutes
|
||||
interval_start: 1
|
||||
interval_end: 1
|
||||
# timeout for answer in minutes
|
||||
timeout: 10
|
||||
streaks: False
|
||||
|
||||
# test channel
|
||||
token: "Nzc4NjQ0MjMxNDI1MDk3NzQx.X7U-8w.TOqNKPWQkNSIRByTRcgkjaZqbUE"
|
||||
#token: NzYwNTI5NDY2MDI3MDE2MjUy.X3NYQg.Nz3bwxgltlayMStfT7F-OCbx9pE
|
||||
@@ -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) VALUES ({str(discordid)}, 1, {reward}, {reward}, 0, 0)"
|
||||
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)"
|
||||
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, limit = 20):
|
||||
def get_top_players(self, column, limit = 20):
|
||||
cursor = self.discorddbconn.get_cursor(dictionary=True)
|
||||
sql = f"SELECT discordid, wins as stat FROM {self.tablename} ORDER BY wins DESC LIMIT {str(limit)}"
|
||||
sql = f"SELECT discordid, {column} as stat FROM {self.tablename} ORDER BY {column} DESC LIMIT {str(limit)}"
|
||||
cursor.execute(sql)
|
||||
return list(cursor.fetchall())
|
||||
|
||||
|
||||
@@ -21,6 +21,6 @@ modPlusRoles = [roleAdmin, roleMod, roleOwner]
|
||||
# Channels
|
||||
ModLogs = 760807882899193867
|
||||
# dev
|
||||
QuizChannelID = 774418250665951232
|
||||
#QuizChannelID = 775776550871498752
|
||||
#QuizChannelID = 774418250665951232
|
||||
QuizChannelID = 775776550871498752
|
||||
DiscordLinkerID = 776944220119760927
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
discord.py==1.5.0
|
||||
mcstatus==4.0.0
|
||||
mysql-connector-python==8.0.21
|
||||
requests==2.25.0
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
from bots.discordbot import DiscordBot
|
||||
import discord.ext.test as dpytest
|
||||
import pytest
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bot():
|
||||
bot = DiscordBot("config.yaml")
|
||||
|
||||
# Load any extensions/cogs you want to in here
|
||||
dpytest.configure(bot.get_client())
|
||||
config = dpytest.get_config()
|
||||
channel = config.channels[0]
|
||||
user = dpytest.backend.make_user("test", 1, 1)
|
||||
member = dpytest.backend.make_member(user, config.guilds[0])
|
||||
guild = config.guilds[0]
|
||||
await dpytest.message("hallo", channel, member)
|
||||
dpytest.verify_message("[Expected help output]")
|
||||
Reference in New Issue
Block a user