most of work for 2.4 done

finished functionality and help,  documentation (readme) not done
- added mention
- finished debug
- improved poll info
- finished cmd
- finished to_command
This commit is contained in:
Matthias Nadler 2019-06-18 18:10:52 +02:00
parent 99898c9a14
commit 13a27bac4a
16 changed files with 471 additions and 45 deletions

57
cogs/admin.py Normal file
View File

@ -0,0 +1,57 @@
import logging
from discord.ext import commands
class Admin(commands.Cog):
def __init__(self, bot):
self.bot = bot
# every commands needs owner permissions
async def cog_check(self, ctx):
return self.bot.owner == ctx.author
async def cog_command_error(self, ctx, error):
if isinstance(error, commands.CheckFailure):
await ctx.send("Only the owner can use this module. Join the support discord server if you are having "
"any problems. This usage has been logged.")
logger.warning(f'User {ctx.author} ({ctx.author.id}) has tried to access a restricted '
f'command via {ctx.message.content}.')
elif isinstance(error, commands.MissingRequiredArgument):
await ctx.send("Missing a required argument for this command.")
else:
logger.warning(error)
@commands.command(aliases=['r'])
async def reload(self, ctx, *, cog):
logger.info(f'Trying to reload cog: cogs.{cog}.')
reply = ''
try:
self.bot.reload_extension('cogs.'+cog)
reply = f'Extension "cogs.{cog}" successfully reloaded.'
except commands.ExtensionNotFound:
reply = f'Extension "cogs.{cog}" not found.'
except commands.NoEntryPointError:
reply = f'Extension "cogs.{cog}" is missing a setup function.'
except commands.ExtensionFailed:
reply = f'Extension "cogs.{cog}" failed to start.'
except commands.ExtensionNotLoaded:
reply = f'Extension "cogs.{cog}" is not loaded... trying to load it. '
try:
self.bot.load_extension('cogs.'+cog)
except commands.ExtensionAlreadyLoaded:
reply += f'Could not load or reload extension since it is already loaded...'
except commands.ExtensionNotFound:
reply += f'Extension "cogs.{cog}" not found.'
except commands.ExtensionFailed:
reply = f'Extension "cogs.{cog}" failed to start.'
finally:
logger.info(reply)
await ctx.send(reply)
def setup(bot):
global logger
logger = logging.getLogger('bot')
bot.add_cog(Admin(bot))

View File

@ -25,6 +25,10 @@ class DiscordBotsOrgAPI(commands.Cog):
if SETTINGS.mode == 'production': if SETTINGS.mode == 'production':
await self.dblpy.post_server_count() await self.dblpy.post_server_count()
logger.info('posted server count ({})'.format(len(self.bot.guilds))) logger.info('posted server count ({})'.format(len(self.bot.guilds)))
sum_users = 0
for guild in self.bot.guilds:
sum_users += len(guild.members)
logger.info(f'total users served by the bot: {sum_users}')
except Exception as e: except Exception as e:
logger.exception('Failed to post server count\n{}: {}'.format(type(e).__name__, e)) logger.exception('Failed to post server count\n{}: {}'.format(type(e).__name__, e))
await asyncio.sleep(1800) await asyncio.sleep(1800)

View File

@ -12,11 +12,10 @@ class Help(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.pages = ['🏠', '🆕', '🔍', '🕹', '🛠', '💖'] self.pages = ['🏠', '🆕', '🔍', '🕹', '🛠', '', '💖']
async def embed_list_reaction_handler(self, ctx, page, pre, msg=None): async def embed_list_reaction_handler(self, ctx, page, pre, msg=None):
embed = self.get_help_embed(page, pre) embed = self.get_help_embed(page, pre)
if msg is None: if msg is None:
msg = await ctx.send(embed=embed) msg = await ctx.send(embed=embed)
# add reactions # add reactions
@ -39,8 +38,6 @@ class Help(commands.Cog):
await reaction.message.remove_reaction(reaction.emoji, user) await reaction.message.remove_reaction(reaction.emoji, user)
return reaction return reaction
def get_help_embed(self, page, pre): def get_help_embed(self, page, pre):
title = f' Pollmaster Help - React with an emoji to learn more about a topic!' title = f' Pollmaster Help - React with an emoji to learn more about a topic!'
@ -49,9 +46,10 @@ class Help(commands.Cog):
embed.set_footer(text='Use reactions to navigate the help. This message will self-destruct in 3 minutes.') embed.set_footer(text='Use reactions to navigate the help. This message will self-destruct in 3 minutes.')
if page == '🏠': if page == '🏠':
## POLL CREATION SHORT # POLL CREATION SHORT
embed.add_field(name='🆕 Making New Polls', embed.add_field(name='🆕 Making New Polls',
value=f'`{pre}quick` | `{pre}new` | `{pre}advanced` | `{pre}prepare` | `{pre}cmd <args>`', inline=False) value=f'`{pre}quick` | `{pre}new` | `{pre}advanced` | `{pre}prepare` | `{pre}cmd <args>`',
inline=False)
# embed.add_field(name='Commands', value=f'`{pre}quick` | `{pre}new` | `{pre}prepared`', inline=False) # embed.add_field(name='Commands', value=f'`{pre}quick` | `{pre}new` | `{pre}prepared`', inline=False)
# embed.add_field(name='Arguments', value=f'Arguments: `<poll question>` (optional)', inline=False) # embed.add_field(name='Arguments', value=f'Arguments: `<poll question>` (optional)', inline=False)
# embed.add_field(name='Examples', value=f'Examples: `{pre}new` | `{pre}quick What is the greenest color?`', # embed.add_field(name='Examples', value=f'Examples: `{pre}new` | `{pre}quick What is the greenest color?`',
@ -59,63 +57,72 @@ class Help(commands.Cog):
## POLL CONTROLS ## POLL CONTROLS
embed.add_field(name='🔍 Show Polls', embed.add_field(name='🔍 Show Polls',
value=f'`{pre}show (label)`', inline=False) value=f'`{pre}show` | `{pre}show <label>` | `{pre}show <category>`', inline=False)
# embed.add_field(name='Command', value=f'`{pre}show (label)`', inline=False) # embed.add_field(name='Command', value=f'`{pre}show (label)`', inline=False)
# embed.add_field(name='Arguments', value=f'Arguments: `open` (default) | `closed` | `prepared` | ' # embed.add_field(name='Arguments', value=f'Arguments: `open` (default) | `closed` | `prepared` | '
# f'`<poll_label>` (optional)', inline=False) # f'`<poll_label>` (optional)', inline=False)
# embed.add_field(name='Examples', value=f'Examples: `{pre}show` | `{pre}show closed` | `{pre}show mascot`', # embed.add_field(name='Examples', value=f'Examples: `{pre}show` | `{pre}show closed` | `{pre}show mascot`',
# inline=False) # inline=False)
## POLL CONTROLS # POLL CONTROLS
embed.add_field(name='🕹 Poll Controls', embed.add_field(name='🕹 Poll Controls',
value=f'`{pre}close` | `{pre}export` | `{pre}delete` | `{pre}activate` ', inline=False) value=f'`{pre}copy` | `{pre}close` | `{pre}export` | `{pre}delete` | `{pre}activate` ',
inline=False)
# embed.add_field(name='Commands', value=f'`{pre}close` | `{pre}export` | `{pre}delete` | `{pre}activate` ', # embed.add_field(name='Commands', value=f'`{pre}close` | `{pre}export` | `{pre}delete` | `{pre}activate` ',
# inline=False) # inline=False)
# embed.add_field(name='Arguments', value=f'Arguments: <poll_label> (required)', inline=False) # embed.add_field(name='Arguments', value=f'Arguments: <poll_label> (required)', inline=False)
# embed.add_field(name='Examples', value=f'Examples: `{pre}close mascot` | `{pre}export proposal`', # embed.add_field(name='Examples', value=f'Examples: `{pre}close mascot` | `{pre}export proposal`',
# inline=False) # inline=False)
## POLL CONTROLS # POLL CONTROLS
embed.add_field(name='🛠 Configuration', embed.add_field(name='🛠 Configuration',
value=f'`{pre}userrole (role)` | `{pre}adminrole (role)` | `{pre}prefix <new_prefix>` ', value=f'`{pre}userrole [role]` | `{pre}adminrole [role]` | `{pre}prefix <new_prefix>` ',
inline=False inline=False
) )
# embed.add_field(name='Commands',
# value=f'`{pre}userrole <role>` | `{pre}adminrole <role>` | `{pre}prefix <new_prefix>` ',
# inline=False)
## ABOUT # DEBUGGING
embed.add_field(name='❔ Debugging',
value=f'`@debug` | `@mention` | `@mention <tag>` ',
inline=False
)
# ABOUT
embed.add_field(name='💖 About Pollmaster', embed.add_field(name='💖 About Pollmaster',
value='More infos about Pollmaster, the developer, where to go for further help and how you can support us.', value='More infos about Pollmaster, the developer, where to go for further help and how you can support us.',
inline=False) inline=False)
elif page == '🆕': elif page == '🆕':
embed.add_field(name='🆕 Making New Polls', embed.add_field(name='🆕 Making New Polls',
value='There are three ways to create a new poll. For all three commands you can either just ' value='There are four ways to create a new poll. For all the commands you can either just '
'type the command or type the command followed by the question to skip that first step.' 'type the command or type the command followed by the question to skip the first step.'
'Your Members need the <admin> or <user> role to use these commands. More in 🛠 Configuration.', 'Your Members need the <admin> or <user> role to use these commands. '
'More on user rights in 🛠 Configuration.',
inline=False) inline=False)
embed.add_field(name=f'🔹 **Quick Poll:** `{pre}quick <poll question>` (optional)', embed.add_field(name=f'🔹 **Quick Poll:** `{pre}quick`',
value='If you just need a quick poll, this is the way to go. All you have to specify is the ' value='If you just need a quick poll, this is the way to go. All you have to specify is the '
'question and your answers; the rest will be set to default values.', 'question and your answers; the rest will be set to default values.',
inline=False) inline=False)
embed.add_field(name=f'🔹 **All Features:** `{pre}new <poll question>` (optional)', embed.add_field(name=f'🔹 **Basic Poll:** `{pre}new`',
value='This command gives you full control over your poll. A step by step wizard will guide ' value='This command gives control over the most common settings. A step by step wizard will guide '
'you through the process and you can specify options such as Multiple Choice, ' 'you through the process and you can specify options such as Multiple Choice, '
'Anonymous Voting, Role Restriction, Role Weights and Deadline.', 'Anonymous Voting and Deadline.',
inline=False) inline=False)
embed.add_field(name=f'🔹 **Prepare and Schedule:** `{pre}prepare <poll question>` (optional)', embed.add_field(name=f'🔹 **Advanced Poll:** `{pre}advanced`',
value=f'Similar to `{pre}new`, this gives you all the options. But additionally, the poll will ' value='This command gives you full control over your poll. A step by step wizard will guide '
'you through the process and you can specify additional options such as Hide Vote Count, '
'Role Restrictions, Role Weights or Custom Write-In Answers (Survey Flags).',
inline=False)
embed.add_field(name=f'🔹 **Prepare and Schedule:** `{pre}prepare`',
value=f'Similar to `{pre}advanced`, this gives you all the options. But additionally, the poll will '
'be set to \'inactive\'. You can specify if the poll should activate at a certain time ' 'be set to \'inactive\'. You can specify if the poll should activate at a certain time '
f'and/or if you would like to manually `{pre}activate` it. ' f'and/or if you would like to manually `{pre}activate` it. '
'Perfect if you are preparing for a team meeting!', 'Perfect if you are preparing for a team meeting!',
inline=False) inline=False)
embed.add_field(name=f'🔹 **-Advanced- Commandline:** `{pre}cmd <args>`', embed.add_field(name=f'🔹 **-Advanced- Commandline:** `{pre}cmd <arguments>`',
value=f'For the full syntax type `{pre}cmd help`\n' value=f'For the full syntax type `{pre}cmd help`\n'
f'Similar to version 1 of the bot, with this command you can create a poll in one message. ' f'Similar to version 1 of the bot, with this command you can create a poll in one message. '
f'Pass all the options you need via command line arguments, the rest will be set to ' f'Pass all the options you need via command line arguments, the rest will be set to '
f'default values. The wizard will step in for invalid arguments.\n' f'default values. The wizard will step in for invalid arguments.\n'
f'Example: `{pre}cmd -q "Which colors?" -l colors -o "green, blue, red" -mc -a`', f'Example: `{pre}cmd -q "Which colors?" -l colors -o "green, blue, red" -h -a`',
inline=False) inline=False)
elif page == '🔍': elif page == '🔍':
@ -137,9 +144,15 @@ class Help(commands.Cog):
inline=False) inline=False)
elif page == '🕹': elif page == '🕹':
embed.add_field(name='🕹 Poll Controls', embed.add_field(name='🕹 Poll Controls',
value='All these commands can only be used by an <admin> or by the author of the poll. ' value='All these commands except copy can only be used by an <admin> or by the author of the poll. '
'Go to 🛠 Configuration for more info on the permissions.', 'Go to 🛠 Configuration for more info on the permissions.',
inline=False) inline=False)
embed.add_field(name=f'🔹 **Copy** `{pre}copy <poll_label>`',
value='This will give you a cmd string that you can post into any channel to create a copy'
'of the specified poll. It will increment the label and depending on the settings, '
'you might need to add missing information like a new deadline. '
f'\nFor more info, see: `{pre}cmd help`.',
inline=False)
embed.add_field(name=f'🔹 **Close** `{pre}close <poll_label>`', embed.add_field(name=f'🔹 **Close** `{pre}close <poll_label>`',
value='Polls will close automatically when their deadline is reached. But you can always ' value='Polls will close automatically when their deadline is reached. But you can always '
'close them manually by using this command. A closed poll will lock in the votes so ' 'close them manually by using this command. A closed poll will lock in the votes so '
@ -180,6 +193,20 @@ class Help(commands.Cog):
'whitespace, use "\w" instead of " " (discord deletes trailing whitespaces).', 'whitespace, use "\w" instead of " " (discord deletes trailing whitespaces).',
inline=False) inline=False)
elif page == '':
embed.add_field(name='❔ Debugging',
value='These commands are independent of your server prefix and serve to debug the bot.',
inline=False)
embed.add_field(name=f'🔹 **Debug:** `@debug`',
value='This command will check the required permissions in the channel it is used and'
'generate a short report with suggestions on your next actions.'
'If you are stuck, please visit the support discord server.',
inline=False)
embed.add_field(name=f'🔹 **Mention:** `@mention` | `@mention prefix`',
value='This is a prefix independent command to retrieve your prefix in case you changed '
'and forgot it. More `@mention` tags might be added in the future.',
inline=False)
elif page == '💖': elif page == '💖':
embed.add_field(name='💖 Pollmaster 💖', embed.add_field(name='💖 Pollmaster 💖',
value='If you enjoy the bot, you can show your appreciation by giving him an upvote on Discordbots.', value='If you enjoy the bot, you can show your appreciation by giving him an upvote on Discordbots.',
@ -205,8 +232,15 @@ class Help(commands.Cog):
return embed return embed
@commands.command() @commands.command()
async def help(self, ctx, *, topic=None): async def help(self, ctx):
server = await ask_for_server(self.bot, ctx.message) server = await ask_for_server(self.bot, ctx.message)
if not server:
return
if not ctx.message.channel.permissions_for(server.me).embed_links:
await ctx.send("Missing permissions. Type \"@debug.\"")
return
pre = await get_server_pre(self.bot, server) pre = await get_server_pre(self.bot, server)
rct = 1 rct = 1
while rct is not None: while rct is not None:
@ -217,13 +251,16 @@ class Help(commands.Cog):
page = rct.emoji page = rct.emoji
msg = rct.message msg = rct.message
rct = await self.embed_list_reaction_handler(ctx, page, pre, msg) rct = await self.embed_list_reaction_handler(ctx, page, pre, msg)
# print(res.user, res.reaction, res.reaction.emoji)
# cleanup # cleanup
try:
await ctx.message.delete() await ctx.message.delete()
except PermissionError:
pass
# @mention and @debug commands
@commands.Cog.listener() @commands.Cog.listener()
async def on_message(self, message): async def on_message(self, message):
if message.content.startswith("@mention "): if message.content.startswith("@mention"):
channel = message.channel channel = message.channel
if not isinstance(channel, discord.TextChannel): if not isinstance(channel, discord.TextChannel):
await channel.send("@mention can only be used in a server text channel.") await channel.send("@mention can only be used in a server text channel.")
@ -234,12 +271,23 @@ class Help(commands.Cog):
await channel.send("Could not determine your server.") await channel.send("Could not determine your server.")
return return
if message.content == "@mention":
await channel.send("The following @mention tags are available:\n🔹 @mention prefix")
return
try:
tag = message.content.split()[1].lower() tag = message.content.split()[1].lower()
except IndexError:
await channel.send("Wrong formatting. Type \"@mention\" or \"@mention <tag>\".")
return
if tag == "prefix": if tag == "prefix":
pre = await get_server_pre(self.bot, guild) pre = await get_server_pre(self.bot, guild)
# await channel.send(f'The prefix for this server/channel is: \n {pre} \n To change it type: \n' # await channel.send(f'The prefix for this server/channel is: \n {pre} \n To change it type: \n'
# f'{pre}prefix <new_prefix>') # f'{pre}prefix <new_prefix>')
await channel.send(pre) await channel.send(pre)
else:
await channel.send(f'Tag "{tag}" not found. Type "@mention" for a list of tags.')
elif message.content == "@debug": elif message.content == "@debug":
channel = message.channel channel = message.channel
@ -253,17 +301,41 @@ class Help(commands.Cog):
return return
status_msg = '' status_msg = ''
setup_correct = True
# check send message permissions
permissions = channel.permissions_for(guild.me) permissions = channel.permissions_for(guild.me)
if not permissions.send_messages: if not permissions.send_messages:
await message.author.send(f'I don\'t have permission to send text messages in channel {channel} ' await message.author.send(f'I don\'t have permission to send text messages in channel "{channel}" '
f'on server {guild}') f'on server "{guild}"')
return return
status_msg += f' ✅ Sending messages\n' status_msg += ' ✅ Sending text messages\n'
# check embed link permissions
if permissions.embed_links:
status_msg += '✅ Sending embedded messages\n'
else:
status_msg += '❗ Sending embedded messages. I need permissions to embed links!\n'
setup_correct = False
# check manage messages
if permissions.manage_messages:
status_msg += '✅ Deleting messages and reactions\n'
else:
status_msg += '❗ Deleting messages and reactions. I need the manage messages permission!\n'
setup_correct = False
if setup_correct:
status_msg += 'No action required. Your permissions are set up correctly for this channel. \n' \
'If the bot does not work, feel free to join the support discord server.'
else:
status_msg += 'Please try to fix the issues above. \nIf you are still having problems, ' \
'visit the support discord server.'
await channel.send(status_msg) await channel.send(status_msg)
def setup(bot): def setup(bot):
global logger global logger
logger = logging.getLogger('bot') logger = logging.getLogger('bot')

View File

@ -518,6 +518,7 @@ class PollControls(commands.Cog):
await poll.set_short(ctx) await poll.set_short(ctx)
await poll.set_anonymous(ctx) await poll.set_anonymous(ctx)
await poll.set_options_reaction(ctx) await poll.set_options_reaction(ctx)
await poll.set_survey_flags(ctx, force='0')
await poll.set_multiple_choice(ctx) await poll.set_multiple_choice(ctx)
await poll.set_hide_vote_count(ctx, force='no') await poll.set_hide_vote_count(ctx, force='no')
await poll.set_roles(ctx, force='all') await poll.set_roles(ctx, force='all')

View File

@ -148,7 +148,7 @@ async def ask_for_channel(ctx, bot, server, message):
def check(m): def check(m):
return message.author.id == m.author.id return message.author.id == m.author.id
try: try:
reply = await bot.wait_for('message', timeout=60) reply = await bot.wait_for('message', timeout=60, check=check)
except asyncio.TimeoutError: except asyncio.TimeoutError:
pass pass
else: else:

View File

@ -0,0 +1,37 @@
--------------------------------------------
POLLMASTER DISCORD EXPORT
--------------------------------------------
Server name (ID): VoteBotTesting (444493407784665108)
Owner of the poll: Newti
Time of creation: 17-Jun-2019 14:45
--------------------------------------------
POLL SETTINGS
--------------------------------------------
Question / Name: asf
Label: LameKestrel
Anonymous: No
# Choices: 1
Answer options: ✅, ❎
Allowed roles: @everyone
Weights for roles: No weights
Deadline: No deadline
--------------------------------------------
POLL RESULTS
--------------------------------------------
Number of participants: 1
Raw results: ✅: 0, ❎: 1
Weighted results: ✅: 0, ❎: 1
Winning option: ❎ with 1 votes
--------------------------------------------
DETAILED POLL RESULTS
--------------------------------------------
Dev|Newti: ❎
--------------------------------------------
BOT DETAILS
--------------------------------------------
Creator: Newti#0654
Link to invite, vote for or support Pollmaster:
https://discordbots.org/bot/444514223075360800
--------------------------------------------
END OF FILE
--------------------------------------------

View File

@ -0,0 +1,37 @@
--------------------------------------------
POLLMASTER DISCORD EXPORT
--------------------------------------------
Server name (ID): VoteBotTesting (444493407784665108)
Owner of the poll: Newti
Time of creation: 17-Jun-2019 14:14
--------------------------------------------
POLL SETTINGS
--------------------------------------------
Question / Name: Oh i forgot
Label: TameOwl
Anonymous: No
# Choices: 1
Answer options: yes, no, maybe
Allowed roles: @everyone
Weights for roles: No weights
Deadline: No deadline
--------------------------------------------
POLL RESULTS
--------------------------------------------
Number of participants: 1
Raw results: yes: 1, no: 0, maybe: 0
Weighted results: yes: 1, no: 0, maybe: 0
Winning option: yes with 1 votes
--------------------------------------------
DETAILED POLL RESULTS
--------------------------------------------
Dev|Newti: yes (test)
--------------------------------------------
BOT DETAILS
--------------------------------------------
Creator: Newti#0654
Link to invite, vote for or support Pollmaster:
https://discordbots.org/bot/444514223075360800
--------------------------------------------
END OF FILE
--------------------------------------------

View File

@ -0,0 +1,37 @@
--------------------------------------------
POLLMASTER DISCORD EXPORT
--------------------------------------------
Server name (ID): VoteBotTesting (444493407784665108)
Owner of the poll: Newti
Time of creation: 17-Jun-2019 15:15
--------------------------------------------
POLL SETTINGS
--------------------------------------------
Question / Name: Aodjasd
Label: kaka
Anonymous: No
# Choices: Multiple
Answer options: abc, def, ghi, jkl
Allowed roles: @everyone
Weights for roles: No weights
Deadline: 17-Jun-2019 15:16 GMT
--------------------------------------------
POLL RESULTS
--------------------------------------------
Number of participants: 1
Raw results: abc: 1, def: 0, ghi: 1, jkl: 0
Weighted results: abc: 1, def: 0, ghi: 1, jkl: 0
Winning options: abc, ghi with 1 votes
--------------------------------------------
DETAILED POLL RESULTS
--------------------------------------------
Dev|Newti: abc, ghi (okay dude this is my textasdasd)
--------------------------------------------
BOT DETAILS
--------------------------------------------
Creator: Newti#0654
Link to invite, vote for or support Pollmaster:
https://discordbots.org/bot/444514223075360800
--------------------------------------------
END OF FILE
--------------------------------------------

View File

@ -0,0 +1,37 @@
--------------------------------------------
POLLMASTER DISCORD EXPORT
--------------------------------------------
Server name (ID): VoteBotTesting (444493407784665108)
Owner of the poll: Newti
Time of creation: 18-Jun-2019 11:03
--------------------------------------------
POLL SETTINGS
--------------------------------------------
Question / Name: asdasd
Label: keke3
Anonymous: Yes
# Choices: 3
Answer options: asd, fgh, jkl, 121, asd
Allowed roles: @everyone
Weights for roles: No weights
Deadline: 18-Jun-2019 11:04 GMT
--------------------------------------------
POLL RESULTS
--------------------------------------------
Number of participants: 1
Raw results: asd: 0, fgh: 1, jkl: 1, 121: 0, asd: 1
Weighted results: asd: 0, fgh: 1, jkl: 1, 121: 0, asd: 1
Winning options: fgh, jkl, asd with 1 votes
--------------------------------------------
LIST OF PARTICIPANTS
--------------------------------------------
Dev|Newti
--------------------------------------------
BOT DETAILS
--------------------------------------------
Creator: Newti#0654
Link to invite, vote for or support Pollmaster:
https://discordbots.org/bot/444514223075360800
--------------------------------------------
END OF FILE
--------------------------------------------

View File

@ -0,0 +1,36 @@
--------------------------------------------
POLLMASTER DISCORD EXPORT
--------------------------------------------
Server name (ID): VoteBotTesting (444493407784665108)
Owner of the poll: Newti
Time of creation: 12-Apr-2019 15:21
--------------------------------------------
POLL SETTINGS
--------------------------------------------
Question / Name: asd
Label: llll
Anonymous: No
Choices: Multiple
Answer options: in favour, against, abstaining
Allowed roles: @everyone
Weights for roles: No weights
Deadline: 12-Apr-2019 21:21 GMT
--------------------------------------------
POLL RESULTS
--------------------------------------------
Number of participants: 1
Raw results: in favour: 0, against: 0, abstaining: 0
Weighted results: in favour: 0, against: 0, abstaining: 0
Winning options: in favour, against, abstaining with 0 votes
--------------------------------------------
DETAILED POLL RESULTS
--------------------------------------------
--------------------------------------------
BOT DETAILS
--------------------------------------------
Creator: Newti#0654
Link to invite, vote for or support Pollmaster:
https://discordbots.org/bot/444514223075360800
--------------------------------------------
END OF FILE
--------------------------------------------

View File

@ -0,0 +1,45 @@
--------------------------------------------
POLLMASTER DISCORD EXPORT
--------------------------------------------
Server name (ID): VoteBotTesting (444493407784665108)
Owner of the poll: Newti
Time of creation: 17-Jun-2019 14:40
--------------------------------------------
POLL SETTINGS
--------------------------------------------
Question / Name: Andasd
Label: okaaydude
Anonymous: Yes
# Choices: Multiple
Answer options: abcd, efg, hji, asd
Allowed roles: @everyone
Weights for roles: No weights
Deadline: 17-Jun-2019 14:50 GMT
--------------------------------------------
POLL RESULTS
--------------------------------------------
Number of participants: 1
Raw results: abcd: 1, efg: 0, hji: 1, asd: 1
Weighted results: abcd: 1, efg: 0, hji: 1, asd: 1
Winning options: abcd, hji, asd with 1 votes
--------------------------------------------
LIST OF PARTICIPANTS
--------------------------------------------
Dev|Newti
--------------------------------------------
CUSTOM ANSWERS (RANDOM ORDER)
--------------------------------------------
abcd:
test
asd:
No Answer
--------------------------------------------
BOT DETAILS
--------------------------------------------
Creator: Newti#0654
Link to invite, vote for or support Pollmaster:
https://discordbots.org/bot/444514223075360800
--------------------------------------------
END OF FILE
--------------------------------------------

View File

@ -0,0 +1,38 @@
--------------------------------------------
POLLMASTER DISCORD EXPORT
--------------------------------------------
Server name (ID): Pollmaster HQ (544514197262696469)
Owner of the poll: Newti
Time of creation: 24-Apr-2019 07:51
--------------------------------------------
POLL SETTINGS
--------------------------------------------
Question / Name: Abcde
Label: abcde
Anonymous: No
# Choices: Multiple
Answer options: abc, def, ghi, jkl
Allowed roles: @everyone
Weights for roles: No weights
Deadline: 24-Apr-2019 08:51 GMT
--------------------------------------------
POLL RESULTS
--------------------------------------------
Number of participants: 2
Raw results: abc: 2, def: 2, ghi: 1, jkl: 1
Weighted results: abc: 2, def: 2, ghi: 1, jkl: 1
Winning options: abc, def with 2 votes
--------------------------------------------
DETAILED POLL RESULTS
--------------------------------------------
Newti: abc, def, ghi, jkl
Page of the Reach: abc, def
--------------------------------------------
BOT DETAILS
--------------------------------------------
Creator: Newti#0654
Link to invite, vote for or support Pollmaster:
https://discordbots.org/bot/444514223075360800
--------------------------------------------
END OF FILE
--------------------------------------------

Binary file not shown.

Binary file not shown.

View File

@ -829,7 +829,7 @@ class Poll:
return m.author == user return m.author == user
try: try:
reply = await self.bot.wait_for('message', timeout=15, check=check) reply = await self.bot.wait_for('message', timeout=120, check=check)
if reply and reply.content: if reply and reply.content:
reply = reply.content reply = reply.content
else: else:
@ -878,7 +878,9 @@ class Poll:
else: else:
cmd += " -o \"" + ", ".join(self.options_reaction) + "\"" cmd += " -o \"" + ", ".join(self.options_reaction) + "\""
if self.survey_flags:
cmd += " -sf \"" + ", ".join([str(x+1) for x in self.survey_flags]) + "\"" cmd += " -sf \"" + ", ".join([str(x+1) for x in self.survey_flags]) + "\""
cmd += " -mc \"" + str(self.multiple_choice) + "\"" cmd += " -mc \"" + str(self.multiple_choice) + "\""
if self.hide_count: if self.hide_count:
cmd += " -h" cmd += " -h"
@ -1408,8 +1410,23 @@ class Poll:
# refresh_poll = False # refresh_poll = False
else: else:
if self.multiple_choice > 0 and self.votes[str(user.id)]['choices'].__len__() >= self.multiple_choice: if self.multiple_choice > 0 and self.votes[str(user.id)]['choices'].__len__() >= self.multiple_choice:
# # auto unvote for single choice non anonymous
# if self.votes[str(user.id)]['choices'].__len__() == 1 and not self.anonymous:
# prev_choice = self.votes[str(user.id)]['choices'][0]
# if self.options_reaction_default:
# emoji = self.options_reaction[prev_choice]
# else:
# emoji = AZ_EMOJIS[prev_choice]
# await message.remove_reaction(emoji, user)
# else:
say_text = f'You have reached the **maximum choices of {self.multiple_choice}** for this poll. ' \ say_text = f'You have reached the **maximum choices of {self.multiple_choice}** for this poll. ' \
f'Before you can vote again, you need to unvote one of your choices.' f'Before you can vote again, you need to unvote one of your choices.\n' \
f'Your current choices are:\n'
for c in self.votes[str(user.id)]['choices']:
if self.options_reaction_default:
say_text += f'{self.options_reaction[c]}\n'
else:
say_text += f'{AZ_EMOJIS[c]} {self.options_reaction[c]}\n'
embed = discord.Embed(title='', description=say_text, colour=SETTINGS.color) embed = discord.Embed(title='', description=say_text, colour=SETTINGS.color)
embed.set_author(name='Pollmaster', icon_url=SETTINGS.author_icon) embed.set_author(name='Pollmaster', icon_url=SETTINGS.author_icon)
await user.send(embed=embed) await user.send(embed=embed)

View File

@ -43,7 +43,7 @@ ch.setFormatter(formatter)
logger.addHandler(fh) logger.addHandler(fh)
logger.addHandler(ch) logger.addHandler(ch)
extensions = ['cogs.config', 'cogs.poll_controls', 'cogs.help', 'cogs.db_api'] extensions = ['cogs.config', 'cogs.poll_controls', 'cogs.help', 'cogs.db_api', 'cogs.admin']
for ext in extensions: for ext in extensions:
bot.load_extension(ext) bot.load_extension(ext)
@ -56,7 +56,6 @@ async def on_ready():
bot.db = mongo.pollmaster bot.db = mongo.pollmaster
bot.session = aiohttp.ClientSession() bot.session = aiohttp.ClientSession()
print(bot.db) print(bot.db)
await bot.change_presence(status=discord.Game(name=f'pm!help - v2.2'))
# check discord server configs # check discord server configs
try: try:
@ -78,11 +77,19 @@ async def on_ready():
bot.locks = {} bot.locks = {}
bot.message_cache = MessageCache(bot) bot.message_cache = MessageCache(bot)
print("Servers verified. Bot running.")
game = discord.Game("Democracy 4")
await bot.change_presence(status=discord.Status.online, activity=game)
print("Servers verified. Bot running.")
@bot.event @bot.event
async def on_command_error(ctx, e): async def on_command_error(ctx, e):
if ctx.cog.qualified_name == "Admin":
# Admin cog handles the errors locally
return
if SETTINGS.log_errors: if SETTINGS.log_errors:
ignored_exceptions = ( ignored_exceptions = (
commands.MissingRequiredArgument, commands.MissingRequiredArgument,
@ -96,7 +103,7 @@ async def on_command_error(ctx, e):
if isinstance(e, ignored_exceptions): if isinstance(e, ignored_exceptions):
# log warnings # log warnings
logger.warning(f'{type(e).__name__}: {e}\n{"".join(traceback.format_tb(e.__traceback__))}') # logger.warning(f'{type(e).__name__}: {e}\n{"".join(traceback.format_tb(e.__traceback__))}')
return return
# log error # log error
@ -117,6 +124,7 @@ async def on_command_error(ctx, e):
# if SETTINGS.mode == 'development': # if SETTINGS.mode == 'development':
raise e raise e
@bot.event @bot.event
async def on_guild_join(server): async def on_guild_join(server):
result = await bot.db.config.find_one({'_id': str(server.id)}) result = await bot.db.config.find_one({'_id': str(server.id)})