issue #6 fix DM char limit for displaying channels

This commit is contained in:
matnad 2019-02-19 17:01:24 +01:00
parent a2be41dded
commit c733d1f4f2
5 changed files with 31 additions and 9 deletions

View File

@ -20,7 +20,7 @@ class DiscordBotsOrgAPI:
while True: while True:
logger.info('attempting to post server count') logger.info('attempting to post server count')
try: try:
await self.dblpy.post_server_count() #await self.dblpy.post_server_count()
logger.info('posted server count ({})'.format(len(self.bot.servers))) logger.info('posted server count ({})'.format(len(self.bot.servers)))
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))

View File

@ -222,7 +222,7 @@ class PollControls:
else: else:
return return
def item_fct(item): def item_fct(i,item):
return f':black_small_square: **{item["short"]}**: {item["name"]}' return f':black_small_square: **{item["short"]}**: {item["name"]}'
title = f' Listing {short} polls' title = f' Listing {short} polls'

View File

@ -1,6 +1,10 @@
import time
import discord import discord
from essentials.settings import SETTINGS from essentials.settings import SETTINGS
from utils.paginator import embed_list_paginated
async def get_pre(bot, message): async def get_pre(bot, message):
'''Gets the prefix for a message.''' '''Gets the prefix for a message.'''
@ -107,13 +111,22 @@ async def ask_for_channel(bot, server, message):
return False return False
# otherwise ask for a channel # otherwise ask for a channel
text = 'Polls are bound to a specific channel on a server. Please select the channel for this poll by typing the corresponding number.\n'
i = 1 i = 1
text = 'Polls are bound to a specific channel on a server. Please select the channel for this poll by typing the corresponding number.\n'
for name in [c.name for c in channel_list]: for name in [c.name for c in channel_list]:
text += f'\n**{i}** - {name}' to_add = f'\n**{i}** - {name}'
i += 1
# check if length doesn't exceed allowed maximum or split it into multiple messages
if text.__len__() + to_add.__len__() > 2048:
embed = discord.Embed(title="Select a channel", description=text, color=SETTINGS.color)
await bot.say(embed=embed)
text = 'Polls are bound to a specific channel on a server. Please select the channel for this poll by typing the corresponding number.\n'
else:
text += to_add
i += 1
embed = discord.Embed(title="Select a channel", description=text, color=SETTINGS.color) embed = discord.Embed(title="Select a channel", description=text, color=SETTINGS.color)
server_msg = await bot.say(embed=embed) await bot.say(embed=embed)
valid_reply = False valid_reply = False
nr = 1 nr = 1

View File

@ -55,6 +55,12 @@ async def on_ready():
print(bot.db) print(bot.db)
await bot.change_presence(game=discord.Game(name=f'V2 IS HERE >> pm!help')) await bot.change_presence(game=discord.Game(name=f'V2 IS HERE >> pm!help'))
await bot.db.config.update_one(
{'_id': '261914618342014977'},
{'$set': {'prefix': 'd!'}},
upsert=True
)
# check discord server configs # check discord server configs
try: try:
db_server_ids = [entry['_id'] async for entry in bot.db.config.find({}, {})] db_server_ids = [entry['_id'] async for entry in bot.db.config.find({}, {})]
@ -97,6 +103,7 @@ async def on_command_error(e, ctx):
# log error # log error
logger.error(f'{type(e).__name__}: {e}\n{"".join(traceback.format_tb(e.__traceback__))}') logger.error(f'{type(e).__name__}: {e}\n{"".join(traceback.format_tb(e.__traceback__))}')
raise e
if SETTINGS.msg_errors: if SETTINGS.msg_errors:
# send discord message for unexpected errors # send discord message for unexpected errors

View File

@ -4,8 +4,9 @@ async def embed_list_paginated(bot, pre, items, item_fct, base_embed, footer_pre
# generate list # generate list
embed.title = f'{items.__len__()} entries' embed.title = f'{items.__len__()} entries'
text = '\n' text = '\n'
for item in items[start:start+per_page]: for i,item in enumerate(items[start:start+per_page]):
text += item_fct(item) + '\n' j = i+start
text += item_fct(j,item) + '\n'
embed.description = text embed.description = text
# footer text # footer text
@ -21,7 +22,8 @@ async def embed_list_paginated(bot, pre, items, item_fct, base_embed, footer_pre
# post / edit message # post / edit message
if msg is not None: if msg is not None:
await bot.edit_message(msg, embed=embed) await bot.edit_message(msg, embed=embed)
await bot.clear_reactions(msg) if str(msg.channel.type) != 'private':
await bot.clear_reactions(msg)
else: else:
msg = await bot.say(embed=embed) msg = await bot.say(embed=embed)