async def run_server(addr: cmyui.Address) -> None: glob.version = cmyui.Version(2, 7, 0) glob.http = aiohttp.ClientSession(json_serialize=orjson.dumps) loop = asyncio.get_event_loop() try: loop.add_signal_handler(signal.SIGINT, lambda: loop.stop()) loop.add_signal_handler(signal.SIGTERM, lambda: loop.stop()) except NotImplementedError: pass glob.db = cmyui.AsyncSQLPoolWrapper() await glob.db.connect(**glob.config.mysql) # Aika glob.bot = Player(id = 1, name = 'Aika', priv = Privileges.Normal) glob.bot.ping_time = 0x7fffffff await glob.bot.stats_from_sql_full() # no need to get friends await glob.players.add(glob.bot) # Add all channels from db. async for chan in glob.db.iterall('SELECT * FROM channels'): await glob.channels.add(Channel(**chan)) async with cmyui.AsyncTCPServer(addr) as glob.serv: plog(f'Gulag v{glob.version} online!', Ansi.LGREEN) async for conn in glob.serv.listen(glob.config.max_conns): asyncio.create_task(handle_conn(conn))
async def run_server(loop: uvloop.Loop, addr: cmyui.Address): glob.version = cmyui.Version(2, 2, 8) glob.http = aiohttp.ClientSession(json_serialize=orjson.dumps) glob.db = cmyui.AsyncSQLPool() await glob.db.connect(loop, **glob.config.mysql) # Aika glob.bot = Player(id=1, name='Aika', priv=Privileges.Normal) glob.bot.ping_time = 0x7fffffff await glob.bot.stats_from_sql_full() # no need to get friends await glob.players.add(glob.bot) # Add all channels from db. async for chan in glob.db.iterall('SELECT * FROM channels'): await glob.channels.add(Channel(**chan)) async with cmyui.AsyncTCPServer(addr) as serv: await plog(f'Gulag v{glob.version} online!', Ansi.LIGHT_GREEN) async for conn in serv.listen(loop, glob.config.max_conns): asyncio.create_task(handle_conn(conn))
from constants.privileges import Privileges from objects.achievement import Achievement from objects.collections import Players from objects.collections import Matches from objects.collections import Channels from objects.collections import Clans from objects.collections import MapPools from objects.player import Player from utils.updater import Updater utils.misc.install_excepthook() # current version of gulag # NOTE: this is used internally for the updater, it may be # worth reading through it's code before playing with it. glob.version = cmyui.Version(3, 3, 3) OPPAI_PATH = Path.cwd() / 'oppai-ng' GEOLOC_DB_FILE = Path.cwd() / 'ext/GeoLite2-City.mmdb' async def fetch_bot_name() -> str: """Fetch the bot's name from the database, if available.""" res = await glob.db.fetch('SELECT name FROM users ' 'WHERE id = 1', _dict=False) if not res: log( "Couldn't find bot account in the database, " "defaulting to BanchoBot for their name.", Ansi.LYELLOW)
from objects.achievement import Achievement from objects.collections import PlayerList from objects.collections import MatchList from objects.collections import ChannelList from objects.collections import ClanList from objects.collections import MapPoolList from objects.player import Player from utils.misc import download_achievement_pngs from utils.updater import Updater __all__ = () # current version of gulag # NOTE: this is used internally for the updater, it may be # worth reading through it's code before playing with it. glob.version = cmyui.Version(3, 2, 4) async def setup_collections() -> None: """Setup & cache many global collections (mostly from sql).""" glob.players = PlayerList() # online players glob.matches = MatchList() # active multiplayer matches glob.channels = await ChannelList.prepare() # active channels glob.clans = await ClanList.prepare() # active clans glob.pools = await MapPoolList.prepare() # active mappools # create our bot & append it to the global player list. res = await glob.db.fetch('SELECT name FROM users WHERE id = 1') glob.bot = Player(
from objects import glob except ModuleNotFoundError as exc: if exc.name == 'config': import shutil shutil.copy('ext/config.sample.py', 'config.py') sys.exit('\x1b[0;92mA config file has been generated, ' 'please configure it to your needs.\x1b[0m') else: raise utils.misc.install_excepthook() # current version of gulag # NOTE: this is used internally for the updater, it may be # worth reading through it's code before playing with it. glob.version = cmyui.Version(3, 4, 1) OPPAI_PATH = Path.cwd() / 'oppai-ng' GEOLOC_DB_FILE = Path.cwd() / 'ext/GeoLite2-City.mmdb' async def setup_collections(db_cursor: aiomysql.DictCursor) -> None: """Setup & cache many global collections.""" # dynamic (active) sets, only in ram glob.players = Players() glob.matches = Matches() # static (inactive) sets, in ram & sql glob.channels = await Channels.prepare(db_cursor) glob.clans = await Clans.prepare(db_cursor) glob.pools = await MapPools.prepare(db_cursor)
from pathlib import Path import cmyui from cmyui import log, Ansi from objects import glob from objects.player import Player from objects.channel import Channel from objects.match import MapPool from constants.privileges import Privileges from utils.updater import Updater # current version of gulag glob.version = cmyui.Version(3, 0, 10) async def on_start() -> None: glob.http = aiohttp.ClientSession(json_serialize=orjson.dumps) # connect to mysql glob.db = cmyui.AsyncSQLPool() await glob.db.connect(glob.config.mysql) # run the sql updater updater = Updater(glob.version) await updater.run() await updater.log_startup() # create our bot & append it to the global player list.
from objects import glob from objects.achievement import Achievement from objects.channel import Channel from objects.clan import Clan from objects.match import MapPool from objects.player import Player from utils.misc import get_press_times from utils.updater import Updater if TYPE_CHECKING: from objects.score import Score __all__ = () # current version of gulag glob.version = cmyui.Version(3, 1, 5) async def on_start() -> None: glob.http = aiohttp.ClientSession(json_serialize=orjson.dumps) # connect to mysql glob.db = cmyui.AsyncSQLPool() await glob.db.connect(glob.config.mysql) # run the sql updater updater = Updater(glob.version) await updater.run() await updater.log_startup() # create our bot & append it to the global player list.