Пример #1
0
    def top(self, event):
        with Timer() as timer:
            top = self.kudos.find(sort=[("count", -1)], limit=5)
            output = "Top 5 kudos are:```"

            names = ""
            points = ""

            for item in top:
                name = item['key']
                count = item['count']

                names += f"{name}\n"
                points += f"{count}\n"

            embed = {
                "fields": [{
                    "name": "Name",
                    "value": names,
                    "inline": True
                }, {
                    "name": "Points",
                    "value": points,
                    "inline": True
                }],
                "footer": {
                    "text": f"⏰ {timer.delta}ms | 🔌 Kudos.top"
                }
            }

            self.say(event.channel_id, "**Top 5 Kudos**: ", embed=embed)
Пример #2
0
    def list_plugins(self, event):
        with Timer() as timer:
            plugins = self.bot.plugins

            names = "".join(
                [type(plugin).__name__ + "\n" for plugin in plugins])
            statuses = "".join(["Enabled" + "\n" for plugin in plugins])

            embed = {
                "color":
                Colors.INFO,
                'fields': [{
                    'name': 'Name',
                    'value': names,
                    "inline": True
                }, {
                    'name': 'Status',
                    'value': statuses,
                    "inline": True
                }],
                "footer": {
                    "text": f"⏰ {timer.delta}ms | 🔌 Manage.list_plugins"
                }
            }
            self.say(event.channel_id, embed=embed)
Пример #3
0
    def define(self, event):
        with Timer() as timer:
            query = event.arguments[1].replace(" ", "+")
            url = f"https://api.urbandictionary.com/v0/define?term={query}"
            response = requests.get(url)
            raw = response.json()

            if not response.status_code == 200:
                self.say(event.channel_id,
                         "Great job, you broke UrbanDictionary")
                return

            defintions = response.json().get('list')

            if not defintions:
                self.say(event.channel_id,
                         "Couldn't find a urban definition for that.")
                return

            definition = defintions[0]['definition']
            example = defintions[0]['example']
            permalink = defintions[0]['permalink']
            word = defintions[0]['word']

            if len(definition + example) > 1800:
                self.say(
                    event.channel_id,
                    "Definition was too long, check it out yourself: {}".
                    format(permalink))
                return

            embed = {
                "title":
                f":book: {word}",
                "url":
                permalink,
                "thumbnail": {
                    "url":
                    "https://upload.wikimedia.org/wikipedia/commons/thumb/8/82/UD_logo-01.svg/250px-UD_logo-01.svg.png"
                },
                "description":
                "͢\n",
                "fields": [{
                    "name": "Definition",
                    "value": definition
                }, {
                    "name": "Example",
                    "value": example
                }],
                "footer": {
                    "text": f"⏰ {timer.delta}ms | 🔌 UrbanDictionary.define"
                }
            }

            self.say(event.channel_id, embed=embed)
Пример #4
0
    def webhook(self, request):
        self.admin_channel_id = "136539488280248320"

        with Timer() as timer:
            data = json.loads(request.stream.read())
            headers = request.headers
            event = headers['X-GITHUB-EVENT']
            embed = None

            if event == 'push':
                embed = self.handle_push(data)
            elif event == 'issues':
                embed = self.handle_issue(data)

            if not embed:
                return

            embed["footer"] = {"text": f"⏰ {timer.delta}ms | 🔌 Github.webhook"}
            self.say(self.admin_channel_id, embed=embed)
Пример #5
0
    def google(self, event):
        with Timer() as timer:
            query = event.arguments[1]
            images = self.search_google(query)
            image_url = random.choice(images)['link']

            embed = {
                "title": f":camera: {query}",
                "url": image_url,
                "image": {
                    "url": image_url,
                    "proxy_url": image_url
                },
                "footer": {
                    "text": f"⏰ {timer.delta}ms | 🔌 Imager.google"
                }
            }

            self.say(event.channel_id, embed=embed)
Пример #6
0
    def update(self):
        for feed in self.feeds:
            with Timer() as timer:
                # Get feed
                parsed_feed = feedparser.parse(feed['url'])
                h = html2text.HTML2Text()
                h.ignore_images = True
                h.ignore_tables = True

                # Check last updated time
                last_checked = feed['last_checked']

                try:
                    if last_checked > parsed_feed.feed['updated_parsed']:
                        continue
                except KeyError:
                    if last_checked > parsed_feed.updated_parsed:
                        continue

                for post in parsed_feed.entries:
                    # Ensure we're going to post something new
                    if last_checked < post['published_parsed']:
                        summary = h.handle(post.summary)
                        summary = summary[:256]
                        timestamp = time.strftime("%a, %b %d %Y @ %I:%M %p",
                                                  post['published_parsed'])

                        embed = {
                            "title": f":satellite: {post.title}",
                            "description":
                            f"**{post.link}**\n*{timestamp}*\n\n{summary}",
                            "footer": {
                                "text": f"⏰ {timer.delta}ms | 🔌 RSS"
                            }
                        }

                        # Post single thing from last update
                        self.say(feed['channel'], embed=embed)
                        feed['last_checked'] = time.gmtime()

                        break
Пример #7
0
 def whoami(self, event):
     with Timer() as timer:
         embed = self.user_card(event.author.id)
         embed['footer'] = {"text": f"⏰ {timer.delta}ms | 🔌 ACL.whoami"}
         self.say(event.channel_id, embed=embed)
Пример #8
0
 def whois(self, event):
     with Timer() as timer:
         embed = self.user_card(event.arguments[1])
         embed['footer'] = {"text": f"⏰ {timer.delta}ms | 🔌 ACL.whois"}
         self.say(event.channel_id, embed=embed)