def create_event_inbox(event, abi_event): meta = event.load_meta() EventInbox.create_from(event) logging.info("create_event_inbox(): from_event_inbox created: %s - from: %s" % (event.event_type, event.from_ship)) if '_to' in meta.keys(): if type(meta['_to']) is int: meta['_to'] = [meta['_to']] for to in meta['_to']: if to != 0: EventInbox.create_to(event, to) logging.info("create_event_inbox(): from_event_inbox created: %s - to: %s" % (event.event_type, to)) else: ships_id = get_ships_in_game(event.game) if ships_id is not None: for ship_id in ships_id: if ship_id != event.from_ship.ship_id: EventInbox.create_to(event, ship_id) logging.info("create_event_inbox(): from_event_inbox created: %s - to: %s" % (event.event_type, ship_id)) else: logging.info("create_event_inbox(): error getting ship ids in game") return False if abi_event.discord: try: msg_vars = {'ship_name': event.from_ship.name, 'ship_id': event.from_ship.ship_id} msg = abi_event.discord_template.format_map(msg_vars) de = DiscordEvent.create(event.game, msg) logging.info("create_event_inbox(): discord event created with id %d" % de.id) except Exception as err: logging.info("create_event_inbox(): error creating discord event: %s" % err) return True
def join_game(event, abi_event): event.from_ship.join_game(event.game) logging.info("join_game(): ship %s joined to %s" % (event.from_ship.ship_id, event.game.name)) Ranking.create(event.from_ship, event.game) logging.info("join_game(): ranking created for %s in game %s" % (event.from_ship.ship_id, event.game.name)) create_welcome_message(event.from_ship) if abi_event.discord: try: msg_vars = {'ship_name': event.from_ship.name, 'ship_id': event.from_ship.ship_id} msg = abi_event.discord_template.format_map(msg_vars) de = DiscordEvent.create(event.game, msg) logging.info("join_game(): discord event created with id %d" % de.id) except Exception as err: logging.info("join_game(): error creating discord event: %s" % err) return True
def exit_game(event, abi_event): event.from_ship.exit_game() logging.info("exit_game(): ship %s removed from game %s" % (event.from_ship.name, event.game.name)) ranking = Ranking.get(event.from_ship, event.game) ranking.delete() logging.info("exit_game(): ship %s removed from ranking in game %s" % (event.from_ship.name, event.game.name)) if abi_event.discord: try: msg_vars = {'ship_name': event.from_ship.name, 'ship_id': event.from_ship.ship_id} msg = abi_event.discord_template.format_map(msg_vars) de = DiscordEvent.create(event.game, msg) logging.info("exit_game(): discord event created with id %d" % de.id) except Exception as err: logging.info("exit_game(): error creating discord event: %s" % err) return True
def post_discord_events(net): games = Game.get_enabled_by_net(net) for game in games: events = DiscordEvent.get_pending_queue(game) for event in events: post_to_discord(event)