def channels_create(token, name, is_public): """ Create a channel using the given parameters """ # Check if name is more than 20 characters long and return InputError if this is the case if len(name) > 20: raise error.InputError( description="The name you entered is more than 20 characters long") # Generate a channel_id for the new channel # Simply done in order of time of creation (1..) # Generation of channel_id will be done in this way as long as ability to delete channels # remains unimplemented num_channels = len(database.get_channels()) channel_id = num_channels + 1 # Use database.set_channel to create channel in the database channel = {'channel_id': channel_id, 'name': name} database.set_channel(channel) channel_data = database.get_channel_data(channel_id) channel_data['is_public'] = is_public database.set_channel_data(channel_data) # User who creates the channel joins it automatically channel_join(token, channel_id) return {'channel_id': channel_id}
async def inspect(ctx, link=None): channel = parse_channel(link) if link == 'all': links = database.get_all_links() msg = 'Found %s link(s):\n' % len(links) for link in links: msg += '⇒ `%s` (%s linked)\n' % (link, len(links[link])) if len(links): await ctx.send(msg) else: await ctx.send('No links found, see `%shelp` for command reference' % config.PREFIX) elif channel: links = database.get_channel_links(channel.id) links = [ '`%s`' % a for a in links ] if len(links): await ctx.send('%s is linked to: %s' % (channel.mention, ', '.join(links))) else: await ctx.send('%s has no links' % channel.mention) elif link: try: channels = database.get_channels(link) channels = [ bot.get_channel(a).mention for a in channels ] await ctx.send('`%s` is connected to: %s' % (link, ', '.join(channels))) except KeyError: await ctx.send('Link `%s` does not exist' % link) else: links = database.get_channel_links(ctx.message.channel.id) links = [ '`%s`' % a for a in links ] if len(links): await ctx.send('This channel is linked to: %s' % ', '.join(links)) else: await ctx.send('This channel has no links')
def madness(): """ Make a data ch = get_channels() parse2(ch, 180, sleep_time=10, update_date=False) """ from database import get_channels ch = get_channels(amount_bottom=10, amount_top=390) parse_1(ch, amount_to_parse=400, sleep_time=100, update_id=True)
def channels_listall(token): """ Returns {channels}, where channels is a list of all channels i.e. {'channels': [{channel_id, name}, {channel_id, name}]} """ # pylint: disable=unused-argument # NB: Supressed this warning because token is in fact used in # the decorator, however pylint doesn't check for this. output = {'channels': []} for channel in database.get_channels(): output['channels'].append(channel) return output
async def unlink(ctx, link): if link == 'all': await ctx.send('Keyword `all` is not allowed as a link name') return try: chans = database.get_channels(link) except KeyError: await ctx.send('Link `%s` does not exist' % link) return if ctx.message.channel.id in chans: database.unlink_channel(ctx.message.channel.id, link) await ctx.send('Channel unlinked from `%s`' % link) else: await ctx.send('Channel was not linked to `%s`, nothing changed' % link)
def channels_list(token): """ Returns {channels}, where channels is a list of channels that the user is part of. i.e. {'channels': [{channel_id, name}, {channel_id, name}]} """ u_id = database.get_current_user(token) output = {'channels': []} # obtain channels so that I can see lists of members # insert channel into the output list if user is a member for channel in database.get_channels(): channeldata = database.get_channel_data(channel['channel_id']) if u_id in channeldata['member_ids']: output['channels'].append(channel) return output
def remove_user(token, u_id): """ Given a u_id, remove the user from the Slackr. """ # we get the current user data terminator = database.get_current_user(token) # Raise AccessError if user is not an owner of the Slackr terminator_perm = database.get_permission_dict(terminator) if terminator_perm['permission_id'] != 1: raise error.AccessError(description="""Action cannot be performed because you are not a Slackr owner.""") # Do a soft remove # they stay a part of everything, but they are removed from owner/memberID # in channels, and they are also banned from ever logging in again. # we get the token of the user to be removed # introduce a new permission ID 66: # terminated and set the user to be removed to perm_id 66: terminated terminated_id = 66 database.set_permissions(u_id, terminated_id) # remove the user from every channel's member_id and owner_id #first we call a list of every channel all_channels = database.get_channels() # we then get the data for each channel for each_channel in all_channels: channel_data = database.get_channel_data(each_channel["channel_id"]) # remove user u_id from owner_ids for owner_id in channel_data['owner_ids']: if u_id == owner_id: channel.channel_removeowner(token, channel_data["channel_id"], u_id) # remove user u_id from member_ids if u_id in channel_data['member_ids']: channel_data['member_ids'].remove(u_id) database.set_channel_data(channel_data) # finally we log the user out of the session (invalidating terminated token) terminated_token = database.get_token_from_user(u_id) if terminated_token is not None: auth.auth_logout(terminated_token)
async def meh(event): sender = await event.get_sender() if '/start' in event.raw_text: await bot.send_message(sender, 'Привет') if not database.is_user_new(sender.id): await bot.send_message(sender, "Выбери категории:", buttons=buttons) else: await bot.send_message(sender, 'Хочешь изменить выбор?', buttons=buttons_to_change) else: await bot.send_message(sender, 'Напиши: /start') f = open('last_date.txt') last_time = f.read() if abs(datetime.datetime.now().hour - int(last_time)) > 0: f = open('last_date.txt', 'w') f.write(str(datetime.datetime.now().hour)) f.close() if abs(datetime.datetime.now().hour - int(last_time)) > 24: database.truncate_all_data() database.truncate_tempdata() ch = database.get_channels(amount_bottom=10, amount_top=390) await parse(ch, 400, sleep_time=10, update_id=True) process_data(probability_sim=0.3, rnn=True) await send_posts(amount_to_send=0) if '/help' in event.raw_text: pass