issue #6 fix DM char limit for displaying channels
This commit is contained in:
parent
a2be41dded
commit
c733d1f4f2
@ -20,7 +20,7 @@ class DiscordBotsOrgAPI:
|
||||
while True:
|
||||
logger.info('attempting to post server count')
|
||||
try:
|
||||
await self.dblpy.post_server_count()
|
||||
#await self.dblpy.post_server_count()
|
||||
logger.info('posted server count ({})'.format(len(self.bot.servers)))
|
||||
except Exception as e:
|
||||
logger.exception('Failed to post server count\n{}: {}'.format(type(e).__name__, e))
|
||||
|
||||
@ -222,7 +222,7 @@ class PollControls:
|
||||
else:
|
||||
return
|
||||
|
||||
def item_fct(item):
|
||||
def item_fct(i,item):
|
||||
return f':black_small_square: **{item["short"]}**: {item["name"]}'
|
||||
|
||||
title = f' Listing {short} polls'
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
import time
|
||||
|
||||
import discord
|
||||
|
||||
from essentials.settings import SETTINGS
|
||||
from utils.paginator import embed_list_paginated
|
||||
|
||||
|
||||
async def get_pre(bot, message):
|
||||
'''Gets the prefix for a message.'''
|
||||
@ -107,13 +111,22 @@ async def ask_for_channel(bot, server, message):
|
||||
return False
|
||||
|
||||
# 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
|
||||
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]:
|
||||
text += f'\n**{i}** - {name}'
|
||||
i += 1
|
||||
to_add = f'\n**{i}** - {name}'
|
||||
|
||||
# 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)
|
||||
server_msg = await bot.say(embed=embed)
|
||||
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)
|
||||
await bot.say(embed=embed)
|
||||
|
||||
valid_reply = False
|
||||
nr = 1
|
||||
|
||||
@ -55,6 +55,12 @@ async def on_ready():
|
||||
print(bot.db)
|
||||
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
|
||||
try:
|
||||
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
|
||||
logger.error(f'{type(e).__name__}: {e}\n{"".join(traceback.format_tb(e.__traceback__))}')
|
||||
raise e
|
||||
|
||||
if SETTINGS.msg_errors:
|
||||
# send discord message for unexpected errors
|
||||
|
||||
@ -4,8 +4,9 @@ async def embed_list_paginated(bot, pre, items, item_fct, base_embed, footer_pre
|
||||
# generate list
|
||||
embed.title = f'{items.__len__()} entries'
|
||||
text = '\n'
|
||||
for item in items[start:start+per_page]:
|
||||
text += item_fct(item) + '\n'
|
||||
for i,item in enumerate(items[start:start+per_page]):
|
||||
j = i+start
|
||||
text += item_fct(j,item) + '\n'
|
||||
embed.description = text
|
||||
|
||||
# footer text
|
||||
@ -21,6 +22,7 @@ async def embed_list_paginated(bot, pre, items, item_fct, base_embed, footer_pre
|
||||
# post / edit message
|
||||
if msg is not None:
|
||||
await bot.edit_message(msg, embed=embed)
|
||||
if str(msg.channel.type) != 'private':
|
||||
await bot.clear_reactions(msg)
|
||||
else:
|
||||
msg = await bot.say(embed=embed)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user