Skip to content

Commit

Permalink
fixed #80
Browse files Browse the repository at this point in the history
  • Loading branch information
s0lst1ce committed Nov 29, 2019
1 parent 01f63a6 commit 2746cca
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 47 deletions.
33 changes: 12 additions & 21 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,35 @@
# #
#########################################


class LanguageConfigEntry(ConfigEntry):
"""docstring for LanguageConfigEntry"""
def __init__(self, bot, cfg_chan_id):
super().__init__()
self.bot = bot
self.cfg_chan_id = cfg_chan_id

async def run(self, ctx):
try:

except Exception as e:
raise e


class MendatoryConfigEntries(ConfigEntry):
"""docstring for ClearanceConfigEntry"""
def __init__(self, bot, cfg_chan_id):
super().__init__(bot, cfg_chan_id)

def is_valid(self, lang):
if lang in ALLOWED_LANGS:
return True
else:
return False


async def run(self, ctx):
try:
#LANGUAGE CONFIG
print("conf")
good = False
while not good:
lang = await self.get_answer(ctx, f"I'm an international robot and tend to opperate in many places. This also means that I speak many language! The list of supported languages can be found on my website {WEBSITE}. So which do you want to speak with?")
if not self.is_valid(lang):
if not self.is_valid(lang.content):
continue
good = True
await ctx.send(f"You have selected {lang}. Glad you could find a language that suits you! If you think the translation is incomplete or could be improved, feel free to improve it. The translations are open to everyone on our {WEBSITE}.")
await ctx.send(f"You have selected {lang.content}. Glad you could find a language that suits you! If you think the translation is incomplete or could be improved, feel free to improve it. The translations are open to everyone on our {WEBSITE}.")

with ConfigFile(ctx.guild.id) as conf:
conf["lang"] = lang
conf["lang"] = lang.content

#ROLE CONFIG
await self.config_channel.send("Role setup is **mendatory** for the bot to work correctly. Otherwise no one will be able to use administration commands.")
await self.config_channel.send("**\nStarting role configuration**\nThis bot uses two level of clearance for its commands.\nThe first one is the **manager** level of clearance. Everyone with a role with this clearance can use commands related to server management. This includes but is not limited to message management and issuing warnings.\nThe second level of clearance is **admin**. Anyone who has a role with this level of clearance can use all commands but the ones related to the bot configuration. This is reserved to the server owner. All roles with this level of clearance inherit **manager** clearance as well.")

new_roles = []
Expand Down Expand Up @@ -154,9 +148,6 @@ async def init(self, ctx):
await self.config_channels[ctx.guild.id].send("**Starting full bot configuration...**")

try:
await self.config_channels[ctx.guild.id].send("Role setup is **mendatory** for the bot to work correctly. Otherwise no one will be able to use administration commands.")
#await ClearanceConfigEntry(self.bot, self.config_channel).run(ctx)

for cog in self.bot.cogs:
if self.bot.cogs[cog].config_entry:
await self.bot.cogs[cog].config_entry(self.bot, self.config_channel).run(ctx)
Expand Down
11 changes: 10 additions & 1 deletion exts/essentials.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Essential features all bot built with this template should have.
Do note that disabling it will cause issues to the config extension."""
import datetime
import logging
import discord
from settings import *
Expand Down Expand Up @@ -147,12 +148,20 @@ async def shutdown(self, ctx):
async def clear(self, ctx, nbr: int):
'''deletes specified <nbr> number of messages in the current channel'''
to_del = []
now = datetime.datetime.now()
async for msg in ctx.channel.history(limit=nbr+1):
local_logger.info("Deleting {}".format(msg))
to_del.append(msg)
if (msg.created_at - now).days <= -14:
await msg.delete()
else:
to_del.append(msg)

try:
await ctx.channel.delete_messages(to_del)

except discord.HTTPException as e:
raise e

except Exception as e:
local_logger.exception("Couldn't delete at least on of{}".format(to_del))
raise e
Expand Down
52 changes: 27 additions & 25 deletions exts/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ async def on_raw_reaction_add(self, payload):

#getting poll_allowed_chans
#@is_init
poll_allowed_chans = ConfigFile(payload.guild_id)

with ConfigFile(payload.guild_id) as conf:
poll_allowed_chans = conf["poll_channels"]

#checking that user isn't the bot
if (payload.user_id != self.bot.user.id) and (payload.channel_id in poll_allowed_chans):
Expand Down Expand Up @@ -134,7 +134,8 @@ async def on_raw_reaction_add(self, payload):
async def on_raw_reaction_remove(self, payload):

#getting poll_allowed_chans
poll_allowed_chans = ConfigFile(payload.guild_id)
with ConfigFile(payload.guild_id) as conf:
poll_allowed_chans = conf["poll_channels"]

#fetching concerned message and the user who added the reaction
message = await self.bot.get_channel(payload.channel_id).fetch_message(payload.message_id)
Expand All @@ -144,26 +145,6 @@ async def on_raw_reaction_remove(self, payload):
#changing color of the embed
await self.balance_poll_color(message, message.reactions[0].count, message.reactions[2].count)

async def balance_poll_color(self, msg, for_count, against_count):
r = g = 128
diff = for_count - against_count
votes = for_count + against_count
r -= (diff/votes)*64
g += (diff/votes)*64

#checking whether the number is over 255
r = int(min(255, r))
g = int(min(255, g))

color = int((r*65536) + (g*256))
#getting messages's embed (there should only be one)
embed = msg.embeds[0].copy()
embed.color = color
await msg.edit(embed=embed)

return msg


@commands.Cog.listener()
async def on_message(self, message):
if message.author==self.bot.user: return
Expand All @@ -173,7 +154,9 @@ async def on_message(self, message):
return

#getting poll_allowed_chans
poll_allowed_chans = ConfigFile(message.guild.id)
#poll_allowed_chans = ConfigFile(message.guild.id)["poll_channels"]
with ConfigFile(message.guild.id) as conf:
poll_allowed_chans = conf["poll_channels"]

if message.channel.id in poll_allowed_chans and message.content.startswith(PREFIX)!=True:

Expand All @@ -188,7 +171,7 @@ async def on_message(self, message):
#making embed
embed_poll = discord.Embed(
title = message.author.name,
description = message.content,
description = discord.utils.escape_mentions(message.content),
colour = discord.Color(16776960),
url = None
)
Expand All @@ -207,6 +190,25 @@ async def on_message(self, message):
except Exception as e:
local_logger.exception("Couldn't send and delete all reaction")

async def balance_poll_color(self, msg, for_count, against_count):
r = g = 128
diff = for_count - against_count
votes = for_count + against_count
r -= (diff/votes)*64
g += (diff/votes)*64

#checking whether the number is over 255
r = int(min(255, r))
g = int(min(255, g))

color = int((r*65536) + (g*256))
#getting messages's embed (there should only be one)
embed = msg.embeds[0].copy()
embed.color = color
await msg.edit(embed=embed)

return msg


@commands.group()
async def poll(self, ctx):
Expand Down
1 change: 1 addition & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
}

HELP_TAB = " "
ALLOWED_LANGS = ["en"]


#########################################
Expand Down

0 comments on commit 2746cca

Please sign in to comment.