From: CMDR furrycat Date: Wed, 11 Oct 2017 08:29:17 +0000 (+0100) Subject: Faction summary channel is optional if a news flash channel is configured. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=115bca763556a268222e9c87799934e58c8b40d9;p=furrycat%2Fcatbot.git Faction summary channel is optional if a news flash channel is configured. --- diff --git a/plugin/faction/faction.py b/plugin/faction/faction.py index 0993073..f957ba5 100644 --- a/plugin/faction/faction.py +++ b/plugin/faction/faction.py @@ -50,7 +50,7 @@ class Faction(DBConnection): def create_tables(self): self.open_db() - cursor = self.query('create table if not exists factions (id char(36) not null, bot_id varchar(32) not null, member_id varchar(32) not null, server_id varchar(32) not null, channel_id varchar(32) not null, newsflash_channel_id varchar(32), faction_id int not null, name varchar(128) not null, state_id int not null, interval int not null default 86400, updated datetime)') + cursor = self.query('create table if not exists factions (id char(36) not null, bot_id varchar(32) not null, member_id varchar(32) not null, server_id varchar(32) not null, channel_id varchar(32), newsflash_channel_id varchar(32), faction_id int not null, name varchar(128) not null, state_id int not null, interval int not null default 86400, updated datetime)') cursor = self.query('create unique index if not exists factions_id on factions (id)') cursor = self.query('create index if not exists factions_bot_id on factions (bot_id)') cursor = self.query('create table if not exists faction_names (faction_id int not null, name varchar(128) not null)') @@ -63,7 +63,7 @@ class Faction(DBConnection): cursor = self.query('create unique index if not exists faction_influence_checksum on faction_influence (checksum, eddb_id, faction_id)') cursor = self.query('create table if not exists faction_trend (checksum char(32) not null, eddb_id int not null, faction_id int not null, state_id int not null, trend int not null, pending boolean)') cursor = self.query('create unique index if not exists faction_trend_state on faction_trend (checksum, eddb_id, faction_id, pending)') - cursor = self.query('create table if not exists systems (id char(36) not null, bot_id varchar(32) not null, member_id varchar(32) not null, server_id varchar(32) not null, name varchar(128) not null, channel_id varchar(32) not null, newsflash_channel_id varchar(32), eddb_id int not null, interval int not null default 86400, updated datetime)') + cursor = self.query('create table if not exists systems (id char(36) not null, bot_id varchar(32) not null, member_id varchar(32) not null, server_id varchar(32) not null, name varchar(128) not null, channel_id varchar(32), newsflash_channel_id varchar(32), eddb_id int not null, interval int not null default 86400, updated datetime)') cursor = self.query('create unique index if not exists systems_id on systems (id)') cursor = self.query('create index if not exists systems_bot_id on systems (bot_id)') self.dbh.commit() @@ -460,7 +460,7 @@ class Faction(DBConnection): text += ' last updated at {}'.format(bot.iso8601(tracked.updated)) else: offset = now - if offset is not None and offset <= now: + if tracked.channel_id and offset is not None and offset <= now: if tracked.interval: text += ' scheduled for {}'.format(bot.iso8601(offset + tracked.interval)) text += '**' @@ -471,7 +471,7 @@ class Faction(DBConnection): text += ' every {}'.format(bot.unparse_seconds(int(tracked.interval))) if tracked.is_private: text += ' in private' - else: + elif tracked.channel_id is not None: text += ' in <#{}>'.format(tracked.channel_id) if tracked.newsflash_channel_id: text += ' news <#{}>'.format(tracked.newsflash_channel_id) @@ -561,18 +561,18 @@ class Faction(DBConnection): await bot.say_many(destination, lines) async def report_tracked_faction(self, tracked): + if tracked.channel_id is None: + return + update = {} update['updated'] = self.now() channel = None - newsflash_channel = None if tracked.is_private: for server in client.servers: try: member = server.get_member(tracked.member_id) channel = await client.start_private_message(member) - if tracked.newsflash_channel_id is not None: - newsflash_channel = channel break except: log.exception('report_tracked_faction') @@ -599,14 +599,11 @@ class Faction(DBConnection): update['updated'] = self.now() channel = None - newsflash_channel = None if tracked.is_private: for server in client.servers: try: member = server.get_member(tracked.member_id) channel = await client.start_private_message(member) - if tracked.newsflash_channel_id is not None: - newsflash_channel = channel break except: log.exception('report_tracked_system') @@ -780,30 +777,28 @@ class Faction(DBConnection): elif arg in ['in', 'news']: if arg == 'in': k = 'channel_id' + s = 'server_id' else: k = 'newsflash_channel_id' + s = 'newsflash_server_id' if param == 'here': if message.channel.is_private: parsed[k] = 'private' - if arg == 'in': - parsed['server_id'] = 'private' + parsed[s] = 'private' ok = True else: parsed[k] = message.channel.id - if arg == 'in': - parsed['server_id'] = message.channel.server.id + parsed[s] = message.channel.server.id ok = True elif param == 'private': parsed[k] = 'private' - if arg == 'in': - parsed['server_id'] = 'private' + parsed[s] = 'private' ok = True elif param: channel = bot.parse_channel(param, author = message.author, voice_ok = False) if channel is not None: parsed[k] = channel.id - if arg == 'in': - parsed['server_id'] = channel.server.id + parsed[s] = channel.server.id ok = True else: break @@ -843,14 +838,14 @@ class Faction(DBConnection): await bot.say(message.channel, 'Who?' if what == 'faction' else 'Where?') return None - if not editing and 'channel_id' not in parsed: + if not editing and 'channel_id' not in parsed and 'newsflash_channel_id' not in parsed: log.info('No channel provided.') await bot.say(message.channel, 'Channel?') return None - if 'newflash_channel_id' in parsed: - if parsed['newsflash_channel_id'] is not None: - if parsed['channel'] == 'private': + if 'newsflash_channel_id' in parsed: + if 'channel_id' in parsed: + if parsed['channel_id'] == 'private': if parsed['newsflash_channel_id'] != 'private': log.info('News flash channel must be private if report channel is private.') await bot.say(message.channel, 'Flash private!') @@ -862,6 +857,9 @@ class Faction(DBConnection): log.info('News flash channel must be on same server.') await bot.say(message.channel, 'Flash channel server!') return None + else: + parsed['server_id'] = parsed['newsflash_server_id'] + del(parsed['newsflash_server_id']) if not editing: parsed['updated'] = self.now()