1
0
Fork 0
mirror of https://gitlab.jonasled.de/jonasled/discordbot synced 2024-05-21 06:35:55 +02:00

fixed typos

This commit is contained in:
Jonas Leder 2020-09-30 11:33:03 +02:00
parent 0402f4ad12
commit 769ac0870b

54
bot.py
View file

@ -187,7 +187,7 @@ async def on_voice_state_update(member, before,
result = dbcursor.execute("SELECT startTime FROM VcActive WHERE user=?", [member.id]).fetchone()[
0] # if yes, get the join time from the database
dbcursor.execute("DELETE FROM VcActive WHERE user=?",
[member.id]) # delete the entrie from the voicechat in the database
[member.id]) # delete the entries from the voicechat in the database
xp = (time() - result) / minutesPerVcXP # calculate the xp
result = dbcursor.execute("SELECT vcXP FROM MESSAGES WHERE user=? AND server = ?",
[member.id, member.guild.id]).fetchone()[
@ -219,7 +219,7 @@ async def on_voice_state_update(member, before,
print(str(member) + " joined the Voicechat " + str(after.channel))
dbcursor.execute("INSERT INTO VcActive VALUES (?, ?)",
[member.id, round(time())]) # insert the current time in the database
dbconnection.commit() # write the changes to databasr
dbconnection.commit() # write the changes to database
return
@ -247,7 +247,7 @@ async def level(ctx,
while len(unsorted) > 0: # do this while we have entries in unsorted
lowest = unsorted[
0] # just set the first entrie in lowest, so we can later overwrite it if we find a user with less XP
0] # just set the first entries in lowest, so we can later overwrite it if we find a user with less XP
for entries in unsorted: # go through every user, calculate the XP and check if its lower than the current lowest
if ((entries[1] + entries[2] + entries[3]) <= (lowest[1] + lowest[2] + lowest[3])):
lowest = entries # if the xp is lower, write the user to lowest
@ -303,7 +303,7 @@ async def leaderboard(ctx):
while len(unsorted) > 0: # do this while we have entries in unsorted
lowest = unsorted[
0] # just set the first entrie in lowest, so we can later overwrite it if we find a user with less XP
0] # just set the first entries in lowest, so we can later overwrite it if we find a user with less XP
for entries in unsorted: # go through every user, calculate the XP and check if its lower than the current lowest
if ((entries[1] + entries[2] + entries[3]) <= (lowest[1] + lowest[2] + lowest[3])):
lowest = entries # if the xp is lower, write the user to lowest
@ -317,12 +317,12 @@ async def leaderboard(ctx):
":eight: ", ":nine: ", ":keycap_ten: "] # the emoji in front of the username
message = "" # in this variable we will prepare in the next step the response
for entries in reversed(
ranking): # loop through every user in reverse order to get the best first and andd his statistics to message
ranking): # loop through every user in reverse order to get the best first and add his statistics to message
message = message + badges[len(ranking) - ranking.index(entries) - 1] + ": <@" + str(
entries[0]) + "> **Total:** " + str(entries[1] + entries[2] + entries[3]) + " XP (**Text:** " + str(
entries[1]) + " + **Reaction:** " + str(entries[2]) + " + **VC:** " + str(entries[3]) + ")\n"
embed = discord.Embed(title="Leaderboard", description=message) # make the response Box
await ctx.message.channel.send(embed=embed) # print the ressponse box
await ctx.message.channel.send(embed=embed) # print the response box
# _
@ -340,10 +340,10 @@ async def ping(ctx): # prints the ping and the time the bot needed to process t
now = datetime.utcnow() # get the current time
if reactOnValidCommand: await ctx.message.add_reaction("")
delta = round((
now.microsecond - ctx.message.created_at.microsecond) / 1000) # substract the time the message was created from the current time 8in microsecconds), convert this to millisecconds and round
now.microsecond - ctx.message.created_at.microsecond) / 1000) # subtract the time the message was created from the current time in microseconds), convert this to milliseconds and round
embed = discord.Embed(title=":ping_pong: | Pong!", description="```prolog\nLatency:: " + str(
round(bot.latency * 1000)) + "ms\nResponse :: " + str(
delta) + "ms```") # make the response, we format it as code and select prolog as language for nice cloloring
delta) + "ms```") # make the response, we format it as code and select prolog as language for nice coloring
await ctx.message.channel.send(embed=embed) # send the prepared message
@ -357,7 +357,7 @@ async def ping(ctx): # prints the ping and the time the bot needed to process t
# _/ | __/ |
# |__/ |___/
@bot.command(brief="prints the text as emojies")
@bot.command(brief="prints the text as emojis")
@commands.cooldown(1, cooldownTime, commands.BucketType.user)
async def emoji(ctx, *message: str): # emojifies the string the user give as parameter
if reactOnValidCommand: await ctx.message.add_reaction("")
@ -392,7 +392,7 @@ async def emoji(ctx, *message: str): # emojifies the string the user give as pa
# |_|
@bot.command(pass_context=True, brief="starts a poll",
description="starts a poll, please give as first argument the question (for sentences please use \") and then the posibilities (leave empty for yes or no)")
description="starts a poll, please give as first argument the question (for sentences please use \") and then the possibilities (leave empty for yes or no)")
@commands.cooldown(1, cooldownTime, commands.BucketType.user)
async def poll(ctx, question, *options: str): # this is a tool to create a poll
if reactOnValidCommand: await ctx.message.add_reaction("")
@ -416,12 +416,12 @@ async def poll(ctx, question, *options: str): # this is a tool to create a poll
for x, option in enumerate(
options): # make a dict from options and process every entry, x is the key and option the value
description += '\n {} {}'.format(reactions[x],
option) # add to the description for every entry in otions one line with the emoji and the answer
option) # add to the description for every entry in options one line with the emoji and the answer
embed = discord.Embed(title=question, description=description) # prepare the response
await ctx.message.channel.send("@everyone") # tag everyone, for the new survey
react_message = await ctx.message.channel.send(embed=embed) # print the survey and save the message to a variable
polls[str(react_message.id)] = [react_message,
ctx.message.author.id] # save the react message and the userid to the polls array to acces it later
ctx.message.author.id] # save the react message and the userid to the polls array to access it later
for reaction in reactions[:len(
options)]: # for every reaction add an entry to the reaction database and add it to the message, that the user can click it
dbcursor.execute("INSERT INTO poll VALUES (?, ?, 0)", [react_message.id, reaction])
@ -453,11 +453,11 @@ async def result(ctx, id): # this function prints the result of a poll
embed = poll_message.embeds[0] # get the embed (the content)
del polls[str(id)] # delte the poll from the poll message array
unformatted_options = [x.strip() for x in poll_message.embeds[0].description.split(
del polls[str(id)] # delete the poll from the poll message array
nonformatted_options = [x.strip() for x in poll_message.embeds[0].description.split(
'\n')] # split the poll options (split every line and remove all leading and trailing spaces)
opt_dict = {}
for options in unformatted_options: # for every option: split on the space between emoji and text and put it in a dict, with the emoji as key and the emoji + the text as value
for options in nonformatted_options: # for every option: split on the space between emoji and text and put it in a dict, with the emoji as key and the emoji + the text as value
options = options.split(" ", 1)
opt_dict[options[0]] = options[0] + " " + options[1]
@ -469,8 +469,8 @@ async def result(ctx, id): # this function prints the result of a poll
embed = discord.Embed(title=poll_message.embeds[0].title, description=description) # prepare the result
embed.set_footer(
text='enden on ' + datetime.now().strftime("%d.%m.%Y %H:%M:%S")) # set as footer the end time of the poll
await poll_message.edit(embed=embed) # edit the origina lmessage and print the results
text='ended on ' + datetime.now().strftime("%d.%m.%Y %H:%M:%S")) # set as footer the end time of the poll
await poll_message.edit(embed=embed) # edit the origin message and print the results
embed2 = discord.Embed(title=" ",
description="You can find the result of the poll in the original message [here](" + poll_message.jump_url + ").") # This message will be printed to the end of the chat with a link to the original (where the results are)
await ctx.message.channel.send(embed=embed2) # print the result message from one line up
@ -495,7 +495,7 @@ async def cat(ctx):
answer = loads(r.text)
extension = answer[0]["url"].split(".")[-1] # get the file extension
r = get(answer[0]["url"]) # get the url to the cat
image_data = BytesIO(r.content) # download tthe image and load it into BytesIO
image_data = BytesIO(r.content) # download the image and load it into BytesIO
image_data.seek(0)
await ctx.send(file=discord.File(image_data, 'cat.' + extension)) # send the cat image
@ -508,7 +508,7 @@ async def dog(ctx):
answer = loads(r.text)
extension = answer["url"].split(".")[-1] # get the file extension
r = get(answer["url"]) # get the url to the dog
image_data = BytesIO(r.content) # download tthe image and load it into BytesIO
image_data = BytesIO(r.content) # download the image and load it into BytesIO
image_data.seek(0)
await ctx.send(file=discord.File(image_data, 'dog.' + extension)) # send the dog image
@ -521,7 +521,7 @@ async def fail(ctx):
"https://api.giphy.com/v1/gifs/random?api_key=0UTRbFtkMxAplrohufYco5IY74U8hOes&tag=fail&pg-13") # get random fail image
answer = loads(r.text)
r = get(answer["data"]["images"]["downsized_medium"]["url"]) # get the url to the fail
image_data = BytesIO(r.content) # download tthe image and load it into BytesIO
image_data = BytesIO(r.content) # download the image and load it into BytesIO
image_data.seek(0)
await ctx.send(file=discord.File(image_data, 'fail.gif')) # send the fail image
@ -576,7 +576,7 @@ async def play(ctx, songURL: str):
titleQue.append(loads(r.text)["title"])
@bot.command(brief="skipps the current song in playlist")
@bot.command(brief="skips the current song in playlist")
@commands.cooldown(1, cooldownTime, commands.BucketType.user)
async def skip(ctx):
try:
@ -586,7 +586,7 @@ async def skip(ctx):
return
if reactOnValidCommand: await ctx.message.add_reaction("")
global player # import the global variable
player.stop() # stop the player (daemon think song enden ==> plays next one)
player.stop() # stop the player (daemon think song ended ==> plays next one)
await ctx.message.channel.send("Skipped current song") # print the status to the console
@ -598,7 +598,7 @@ async def que(ctx):
message = "**Musicbot Que:**\n **[current] " + titleQue[
0] + " **" # prepare the message and add the current playing first in bold
for entries in titleQue[1:]: # scroll through the entries and add all songs to the resonse
for entries in titleQue[1:]: # scroll through the entries and add all songs to the response
message = message + "\n" + entries
await ctx.message.channel.send(message) # send the prepared message
@ -619,10 +619,10 @@ async def stop(ctx):
global downloadQue
global playerServer
if (playerServer != ctx.message.guild.id): # check if the music bot runns on this server
if (playerServer != ctx.message.guild.id): # check if the music bot runs on this server
await ctx.message.channel.send("You can't stop the music bot on a different server.")
return
playerQue = [] # delte all ques
playerQue = [] # delete all ques
titleQue = []
downloadQue = []
player.stop() # stop the current song
@ -652,7 +652,7 @@ async def volume(ctx, volume: int):
audioPlayer.volume = volume / 100 # change the volume
async def checkForNextSong(): # background task, that runns every seccond and checks if the song ended
async def checkForNextSong(): # background task, that runs every second and checks if the song ended
global player # import the global variables
global playerQue
global playerServer
@ -690,7 +690,7 @@ async def checkForNextSong(): # background task, that runns every seccond and c
audioPlayer = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(filename, **{
'options': '-vn'})) # convert the audio player to a volume audio player
player.play(audioPlayer)
await sleep(1) # sleep 1 seccond and allo the bot to run different tasks
await sleep(1) # sleep 1 second and allow the bot to run different tasks
except:
pass