|
1
|
|
|
""" |
|
2
|
|
|
Cog with role related commands available in the Bot. |
|
3
|
|
|
|
|
4
|
|
|
Current commands: |
|
5
|
|
|
/remove_spot |
|
6
|
|
|
|
|
7
|
|
|
""" |
|
8
|
|
|
import discord |
|
9
|
|
|
from discord.ext import commands |
|
10
|
|
|
from discord.utils import get |
|
11
|
|
|
import cogs.cogbase as cogbase |
|
12
|
|
|
from cogs.databasecog import DatabaseCog |
|
13
|
|
|
|
|
14
|
|
|
monster_type_dict = {0: "rare", 1: "legendary", 2: "event1", 3: "event2", 4: "common"} |
|
15
|
|
|
|
|
16
|
|
|
prefix = "/" |
|
17
|
|
|
cords_beginning = ["-", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
class SpotCog(cogbase.BaseCog): |
|
21
|
|
|
def __init__(self, base): |
|
22
|
|
|
super().__init__(base) |
|
23
|
|
|
self.peepo_ban_emote = ":peepoban:872502800146382898" |
|
24
|
|
|
|
|
25
|
|
|
# Ping monster role |
|
26
|
|
|
@commands.Cog.listener() |
|
27
|
|
|
async def on_message(self, ctx): |
|
28
|
|
|
if ctx.author.id == self.bot.user.id: |
|
29
|
|
|
return |
|
30
|
|
|
|
|
31
|
|
|
# If common spotted |
|
32
|
|
|
try: |
|
33
|
|
|
if ctx.channel.id == self.bot.ch_common: |
|
34
|
|
|
await self.handle_spotted_common(ctx) |
|
35
|
|
|
elif ctx.channel.category and ctx.channel.category.id == self.bot.cat_spotting: |
|
36
|
|
|
await self.handle_spotted_monster(ctx) |
|
37
|
|
|
except AttributeError: |
|
38
|
|
|
pass |
|
39
|
|
|
|
|
40
|
|
|
@staticmethod |
|
41
|
|
|
async def handle_spotted_common(ctx): |
|
42
|
|
|
if ctx.content[0] in cords_beginning: |
|
43
|
|
|
await DatabaseCog.db_count_spot(ctx.author.id, "common") |
|
44
|
|
|
await DatabaseCog.db_save_coords(ctx.content, "common") |
|
45
|
|
|
else: |
|
46
|
|
|
await ctx.delete() |
|
47
|
|
|
|
|
48
|
|
|
async def handle_spotted_monster(self, ctx): |
|
49
|
|
|
if ctx.content.startswith(prefix): |
|
50
|
|
|
spotted_monster = self.get_monster(ctx, ctx.content.replace(prefix, "")) |
|
51
|
|
|
if spotted_monster: |
|
52
|
|
|
monster_type_str = monster_type_dict[spotted_monster["type"]] |
|
53
|
|
|
if await self.wrong_channel(ctx, spotted_monster, monster_type_str): |
|
54
|
|
|
return |
|
55
|
|
|
role = get(ctx.guild.roles, name=spotted_monster["name"]) |
|
56
|
|
|
await ctx.delete() |
|
57
|
|
|
await ctx.channel.send(f"{role.mention}") |
|
58
|
|
|
await DatabaseCog.db_count_spot(ctx.author.id, |
|
59
|
|
|
monster_type_str) |
|
60
|
|
|
logs_ch = self.bot.get_channel(self.bot.ch_logs) |
|
61
|
|
|
await logs_ch.send(f"[PingLog] {ctx.author} ({ctx.author.id}) " |
|
62
|
|
|
f"requested ping for **{spotted_monster['name']}**") |
|
63
|
|
|
else: |
|
64
|
|
|
await ctx.delete() |
|
65
|
|
|
await ctx.channel.send( |
|
66
|
|
|
f"{ctx.author.mention} monster not found - are you sure that the name is correct?", delete_after=5) |
|
67
|
|
|
elif len(ctx.content) > 0 and ctx.content[0] in cords_beginning: |
|
68
|
|
|
await DatabaseCog.db_save_coords(ctx.content, ctx.channel.name) |
|
69
|
|
|
elif ctx.channel.id == self.bot.ch_legendary_spot or ctx.channel.id == self.bot.ch_rare_spot: |
|
70
|
|
|
await ctx.add_reaction(f"a{self.peepo_ban_emote}") |
|
71
|
|
|
|
|
72
|
|
|
async def wrong_channel(self, ctx, spotted_monster, monster_type_str): |
|
73
|
|
|
if ctx.channel.id in [self.bot.ch_legendary_spot, self.bot.ch_rare_spot]: |
|
74
|
|
|
if ctx.channel.name != monster_type_str: |
|
75
|
|
|
channel = discord.utils.get(ctx.guild.channels, name=monster_type_str) |
|
76
|
|
|
correct_channel = channel.id |
|
77
|
|
|
await ctx.delete() |
|
78
|
|
|
await ctx.channel.send( |
|
79
|
|
|
f"{ctx.author.mention} you posted {spotted_monster['name']} on wrong channel! " |
|
80
|
|
|
f"Use <#{correct_channel}> instead! <{self.peepo_ban_emote}>", delete_after=8) |
|
81
|
|
|
return True |
|
82
|
|
|
return False |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
def setup(bot: commands.Bot): |
|
86
|
|
|
bot.add_cog(SpotCog(bot)) |
|
87
|
|
|
|