def test_builtin_function_name_completion(completer): result = result_set(completer, 'SELECT MAX') assert result == { function('MAX', -3), function('MAX_VALID_TIMESTAMP()', -3), keyword('MAXEXTENTS', -3) }
def test_columns_before_keywords(completer): text = 'SELECT * FROM orders WHERE s' completions = get_result(completer, text) col = column('status', -1) kw = keyword('SELECT', -1) assert completions.index(col) < completions.index(kw)
def test_user_function_name_completion(completer): result = result_set(completer, 'SELECT cu') assert result == { function('Custom_Fun', -2), function('Custom_Func1', -2), function('custom_func2', -2), function('CURRENT_TIMESTAMP()', -2), keyword('CURRENT', -2) }
async def barbarian_(self, ctx, village: CoordinateConverter, *, options=None): radius, points = utils.keyword(options, **self.base_options) kwargs = { 'radius': radius, 'points': points, 'extra': ' AND village.player = 0' } result = await self.fetch_in_radius(ctx.server, village, **kwargs) await self.send_result(ctx, result, "Barbarendörfer")
async def netflix_(self, ctx, *, args=None): """Returns random german netflix movie, specify further with these keywords: year, rating and runtime. Keywords are used like this: key=value. You can use both <> operators as well. For example .netflix year>2000 rating>5 which would return all movies released after 2000 with a rating more than 5""" kwargs = {'rating': None, 'year': None, 'runtime': None} genre, rating, year, runtime = keyword(args, strip=True, **kwargs) possible_movies = [] await self._lock.wait() for movie in self.movies.values(): if genre and genre not in movie.description: continue if not rating.compare(movie.rating): continue if not year.compare(movie.year): continue if runtime: input_sec = input_to_seconds(runtime.value) if not year.compare(input_sec, movie.seconds): continue possible_movies.append(movie) if not possible_movies: msg = "sadly no movies were able to meet your requirements" await ctx.send(msg) else: movie = random.choice(possible_movies) embed = self.create_movie_embed(movie) await ctx.send(embed=embed)
def test_select_keyword_completion(completer): result = result_set(completer, 'SEL') assert result == {keyword('SELECT', -3)}
async def map_(self, ctx, *, arguments=None): options = {'zoom': [0, 5], 'top': [5, 10, 20], 'player': False, 'label': True} tribe_names, zoom, top, player, label = keyword(arguments, strip=True, **options) await ctx.trigger_typing() color_map = [] if not tribe_names: file = self.top10_cache.get(ctx.server) if arguments is None and file is not None: file.seek(0) await ctx.send(file=discord.File(file, 'map.png')) return ds_type = "player" if player else "tribe" ds_objects = await self.bot.fetch_top(ctx.server, ds_type, till=top.value) else: all_tribes = [] raw_fractions = tribe_names.split('&') fractions = [f for f in raw_fractions if f] for index, team in enumerate(fractions): names = [] quoted = re.findall(r'\"(.+)\"', team) for res in quoted: team = team.replace(f'"{res}"', ' ') names.append(res) for name in team.split(): if not name: continue names.append(name) all_tribes.extend(names) if len(fractions) == 1 and '&' not in tribe_names: color_map.extend([obj] for obj in names) else: color_map.append(names) ds_objects = await self.bot.fetch_bulk(ctx.server, all_tribes, 1, name=True) if len(color_map) > 20: return await ctx.send("Du kannst nur bis zu 20 Stämme/Gruppierungen angeben") colors = self.colors.top() for tribe in ds_objects.copy(): if not tribe_names: tribe.color = colors.pop(0) continue for index, group in enumerate(color_map): names = [t.lower() for t in group] if tribe.tag.lower() in names: tribe.color = colors[index] break else: ds_objects.remove(tribe) all_villages = await self.bot.fetch_all(ctx.server, "map") if not all_villages: msg = "Auf der Welt gibt es noch keine Dörfer :/" return await ctx.send(msg) ds_dict = {dsobj.id: dsobj for dsobj in ds_objects} if player: args = (all_villages, {}, ds_dict) else: result = await self.bot.fetch_tribe_member(ctx.server, list(ds_dict)) players = {pl.id: pl for pl in result} args = (all_villages, ds_dict, players) kwargs = {'zoom': zoom.value, 'label': label.value} file = await self.send_map(ctx, *args, **kwargs) if arguments is None: self.top10_cache[ctx.server] = file else: file.close()
async def graveyard_(self, ctx, village: CoordinateConverter, *, options=None): args = utils.keyword(options, **self.base_options, since=[1, 3, 14], tribe=None) radius, points, inactive_since, tribe = args all_villages = await self.fetch_in_radius(ctx.server, village, radius=radius) player_ids = set([vil.player_id for vil in all_villages]) base = [] for num in range(inactive_since.value + 1): table = f"player{num or ''}" query_part = f'SELECT * FROM {table} ' \ f'WHERE {table}.world = $1 ' \ f'AND {table}.id = ANY($2)' if tribe.value in [True, False]: state = '!=' if tribe.value else '=' query_part += f' AND {table}.tribe_id {state} 0' base.append(query_part) query = ' UNION ALL '.join(base) async with self.bot.pool.acquire() as conn: cache = await conn.fetch(query, ctx.server, player_ids) result = [utils.Player(rec) for rec in cache] player_cache = {} day_counter = Counter() for player in result: last = player_cache.get(player.id) if last is None: if not points.compare(player.points): player_cache[player.id] = False else: player_cache[player.id] = player elif last is False: continue elif last.points <= player.points and last.att_bash == player.att_bash: player_cache[player.id] = player day_counter[player.id] += 1 else: player_cache[player.id] = False result = [] for player_id, player in player_cache.items(): if day_counter[player_id] != inactive_since.value: continue else: result.append(player) await self.send_result(ctx, result, "inaktiven Spieler")