<commit_before>#!/usr/bin/env python3.6
# encoding: utf-8

import logging

import aiocache
import aiofiles
import asyncpg
import discord
from discord.ext import commands


logger = logging.getLogger('cogs.db')
cached = aiocache.cached(ttl=20, serializer=None)


class Database:
	SETTINGS_UPDATED_MESSAGE = (
		'\N{white heavy check mark} Done. '
		'Note that it may take up to twenty seconds for your changes to take effect.')

	def __init__(self, bot):
		self.bot = bot
		self._init_task = self.bot.loop.create_task(self._init())

	def __unload(self):
		self._init_task.cancel()

		try:
			self.bot.loop.create_task(self.pool.close())
		except AttributeError:
			pass

	async def _init(self):
		credentials = self.bot.config['database']
		# god bless kwargs
		self.pool = await asyncpg.create_pool(**credentials)

		async with aiofiles.open('data/schema.sql') as f:
			schema = await f.read()
		await self.pool.execute(schema)

		logger.info('Database connection initialized successfully')

	async def set_poll_emoji(self, channel: int, yes, no, shrug):
		# mfw no INSERT OR REPLACE in postgres
		await self.pool.execute("""
			INSERT INTO poll_emoji (channel, yes, no, shrug)
			VALUES ($1, $2, $3, $4)
			ON CONFLICT (channel)
			DO UPDATE SET
				yes   = EXCLUDED.yes,
				no    = EXCLUDED.no,
				shrug = EXCLUDED.shrug
		""", channel, yes, no, shrug)

	@cached
	async def get_poll_emoji(self, channel: int):
		return tuple(await self.pool.fetchrow("""
			SELECT yes, no, shrug
			FROM poll_emoji
			WHERE channel = $1
		""", channel))

	@commands.command(name='set-emoji')
	@commands.has_permissions(manage_emojis=True)<commit_msg>cogs/db.get_poll_emoji: fix TypeError<commit_after>#!/usr/bin/env python3.6
# encoding: utf-8

import logging

import aiocache
import aiofiles
import asyncpg
import discord
from discord.ext import commands


logger = logging.getLogger('cogs.db')
cached = aiocache.cached(ttl=20, serializer=None)


class Database:
	SETTINGS_UPDATED_MESSAGE = (
		'\N{white heavy check mark} Done. '
		'Note that it may take up to twenty seconds for your changes to take effect.')

	def __init__(self, bot):
		self.bot = bot
		self._init_task = self.bot.loop.create_task(self._init())

	def __unload(self):
		self._init_task.cancel()

		try:
			self.bot.loop.create_task(self.pool.close())
		except AttributeError:
			pass

	async def _init(self):
		credentials = self.bot.config['database']
		# god bless kwargs
		self.pool = await asyncpg.create_pool(**credentials)

		async with aiofiles.open('data/schema.sql') as f:
			schema = await f.read()
		await self.pool.execute(schema)

		logger.info('Database connection initialized successfully')

	async def set_poll_emoji(self, channel: int, yes, no, shrug):
		# mfw no INSERT OR REPLACE in postgres
		await self.pool.execute("""
			INSERT INTO poll_emoji (channel, yes, no, shrug)
			VALUES ($1, $2, $3, $4)
			ON CONFLICT (channel)
			DO UPDATE SET
				yes   = EXCLUDED.yes,
				no    = EXCLUDED.no,
				shrug = EXCLUDED.shrug
		""", channel, yes, no, shrug)

	@cached
	async def get_poll_emoji(self, channel: int):
		return await self.pool.fetchrow("""
			SELECT yes, no, shrug
			FROM poll_emoji
			WHERE channel = $1
		""", channel)

	@commands.command(name='set-emoji')
	@commands.has_permissions(manage_emojis=True)
{'fraction_non_alphanumeric': 0.11941659070191431, 'fraction_numerical': 0.006077180188392586, 'mean_word_length': 4.056835637480798, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2061637', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1140, 'n_words': 305}