def guilds_auditlogs_list(self, guild, before=None, user_id=None, action_type=None, limit=50): r = self.http( Routes.GUILDS_AUDITLOGS_LIST, dict(guild=guild), params=optional( before=before, user_id=user_id, action_type=int(action_type) if action_type else None, limit=limit, )) data = r.json() users = User.create_hash(self.client, 'id', data['users']) webhooks = Webhook.create_hash(self.client, 'id', data['webhooks']) return AuditLogEntry.create_map(self.client, r.json()['audit_log_entries'], users, webhooks, guild_id=guild)
def webhooks_token_modify(self, webhook, token, name=None, avatar=None): r = self.http(Routes.WEBHOOKS_TOKEN_MODIFY, dict(webhook=webhook, token=token), json=optional( name=name, avatar=avatar, )) return Webhook.create(self.client, r.json())
def channels_webhooks_create(self, channel, name=None, avatar=None): r = self.http(Routes.CHANNELS_WEBHOOKS_CREATE, dict(channel=channel), json=optional( name=name, avatar=avatar, )) return Webhook.create(self.client, r.json())
def webhooks_modify(self, webhook, name=None, avatar=None, reason=None): r = self.http(Routes.WEBHOOKS_MODIFY, dict(webhook=webhook), json=optional( name=name, avatar=avatar, ), headers=_reason_header(reason)) return Webhook.create(self.client, r.json())
def webhook_circle_ci(): data = request.json['payload'] embed = MessageEmbed() if data['outcome'] == 'success': embed.color = 0x42c88a else: embed.color = 0xed5c5c embed.title = 'Build #{} - {} ({})'.format( data['build_num'], data['subject'], data['author_name'], ) embed.url = data['build_url'] steps = [] for step in data['steps']: emoji = ':x:' if any( True for act in step['actions'] if act.get('failed', False)) else ':white_check_mark:' steps.append('{} - {}'.format(emoji, step['name'])) embed.description = '\n'.join(steps) embed.description += '\n [View Diff]({})'.format(data['compare']) Webhook.execute_url(current_app.config.get('WEBHOOK_URL'), embeds=[embed]) if data['outcome'] != 'success': return subprocess.Popen(['git', 'pull', 'origin', 'master']).wait() rdb.publish('actions', json.dumps({ 'type': 'RESTART', })) return '', 200
def webhooks_token_get(self, webhook, token): r = self.http(Routes.WEBHOOKS_TOKEN_GET, dict(webhook=webhook, token=token)) return Webhook.create(self.client, r.json())
def webhooks_get(self, webhook): r = self.http(Routes.WEBHOOKS_GET, dict(webhook=webhook)) return Webhook.create(self.client, r.json())
def guilds_webhooks_list(self, guild): r = self.http(Routes.GUILDS_WEBHOOKS_LIST, dict(guild=guild)) return Webhook.create_map(self.client, r.json())
def channels_webhooks_list(self, channel): r = self.http(Routes.CHANNELS_WEBHOOKS_LIST, dict(channel=channel)) return Webhook.create_map(self.client, r.json())
def send_webhook(embed, url): return Webhook.execute_url(url, embeds=[embed])