def watch(bot_id, minutes): """ Watch the online status of a bot. If the watched bot goes offline you will be sent a DM informing you. Providing the minutes parameter will mean a DM is only sent if the watched bot has been offline for at least that number of minutes. This command must be issued in a guild that has both Monitoro and the bot to be watched as members. \b Examples: monitoro watch 737425645771948123 monitoro watch --minutes 5 737425645771948123 """ guild_id = get_conversation().message.get("guild_id") if not guild_id: click.echo(f"This command must be issued in a guild") click.get_current_context().abort() watching = discord.get_guild_member(smalld, guild_id, bot_id) if not watching or not watching.user.get("bot", False): click.echo(f"{bot_id} is not a bot in this guild") click.get_current_context().abort() watcher_id = get_conversation().user_id watchers.add(bot_id=bot_id, watcher_id=watcher_id, minutes=minutes) smalld.send_gateway_payload({ "op": 8, "d": { "guild_id": guild_id, "limit": 1, "presences": True, "user_ids": bot_id, }, }) click.echo( f"You are now watching **{watching.user.username}** (<@!{watching.user.id}>)" )
def github_from_channel(config: Config) -> Optional[str]: conversation = smalld_click.get_conversation() if not conversation: return None channel = next( (name for name, channel_id in config.discord_channels.items() if channel_id == conversation.channel_id), None, ) return config.github_repositories.get(channel)
def unwatch(bot_id): """ Stop watching the online status of a bot. \b Example: monitoro unwatch 737425645771948123 """ watching = discord.get_user(smalld, bot_id) watcher_id = get_conversation().user_id watchers.remove(bot_id=bot_id, watcher_id=watcher_id) who = f"**{watching.username}**" if watching.get("bot", False) else bot_id click.echo(f"You have stopped watching {who}")
def status(): """ Display the status of all bots you are watching. The status may be online (green checkmark), offline (red cross), or unknown (question mark). A bot's status being unknown means that Monitoro has not seen any presence change event for that bot yet. \b Example: monitoro status """ watcher_id = get_conversation().user_id for bot in sorted( (discord.get_user(smalld, bot_id) for bot_id in watchers.get_watching(watcher_id)), key=lambda b: b.username.lower(), ): icon = STATUS_ICONS[statuses[bot.id]] click.echo(f"{icon} {bot.username} ({bot.id})")
def find_github_auth() -> Optional[GithubAuth]: conversation = smalld_click.get_conversation() return auth_dao.find( conversation.user_id) if conversation else auth_from_env()
def about(): """ Display information and stats about Monitoro. \b Example: monitoro about """ channel_id = get_conversation().channel_id pkg = get_distribution("monitoro") bots, users = watchers.get_counts() stats_line = f"Watching **{bots} bots** for **{users} users**." uptime = humanize.precisedelta(datetime.now() - start_time, format="%.0f", minimum_unit="minutes") def github_link(org, repo, name=None): return f"[{name or repo}](https://github.com/{org}/{repo})" stack = { ("ianagbip1oti", "monitoro"): pkg.version, ("aymanizz", "smalld-click"): smalld_click_version, ("princesslana", "smalld"): smalld_version, } stack_info = "\n".join(f"{github_link(*repo)}: {version}" for repo, version in stack.items()) smalld.post( f"/channels/{channel_id}/messages", { "embed": { "title": "Monitoro", "description": "Discord bot for monitoring the online status of Discord bots", "thumbnail": { "url": ("https://raw.githubusercontent.com/" "ianagbip1oti/monitoro/master/avatar.png") }, "fields": [ { "name": "Stats", "value": stats_line }, { "name": "Prefix", "value": NAME, "inline": True }, { "name": "Links", "value": "\n".join(( github_link("ianagbip1oti", "monitoro", name="Source on GitHub"), "[Discord Bot List](https://top.gg/bot/737425645771948123)", )), "inline": True, }, { "name": "Uptime", "value": uptime, "inline": True }, { "name": "Stack", "value": stack_info }, { "name": "Icon", "value": ("Made by [Freepik](http://www.freepik.com/) " "from [www.flaticon.com](https://www.flaticon.com)"), }, ], } }, )
def command(): nonlocal conversation conversation = get_conversation()
def command(): nonlocal msg1, msg2 conv = get_conversation() msg1 = conv.message click.prompt("prompt") msg2 = conv.message