Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

v2.0.0 #158

Merged
merged 202 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
202 commits
Select commit Hold shift + click to select a range
c609864
Added connection to postresql database
Galarzaa90 Sep 27, 2018
196932d
Create characters database on startup
Galarzaa90 Sep 29, 2018
54436bd
Added more table, function and trigger schemas
Galarzaa90 Sep 29, 2018
5ecdf8b
Importing characters, deaths and leveups from sqlite database
Galarzaa90 Sep 29, 2018
3726b06
Fixed deaths and levelup migration
Galarzaa90 Oct 3, 2018
c9b43db
Added server_properties migration
Galarzaa90 Oct 3, 2018
2c74e3d
Added auxiliary methods to NabCtx
Galarzaa90 Oct 5, 2018
d38c67f
Updated get_character() to use postgresql database
Galarzaa90 Oct 5, 2018
f115d08
Settings cog now uses postgresql
Galarzaa90 Oct 6, 2018
c51f2ff
Prefixes are saved in their own table for faster access
Galarzaa90 Oct 6, 2018
eb11b66
Small changes to character tracking
Galarzaa90 Oct 7, 2018
269c540
Cleaned up tracking tasks (untested)
Galarzaa90 Oct 8, 2018
fcba048
Reenabled tracking tasks
Galarzaa90 Oct 8, 2018
90a9e44
Fixes to character tracking
Galarzaa90 Oct 8, 2018
cbaaaa3
/deaths command now uses postgresql
Galarzaa90 Oct 8, 2018
d617881
Migrated /death subcommands to postgresql
Galarzaa90 Oct 9, 2018
58b9a70
/levels now use postgresql
Galarzaa90 Oct 9, 2018
491a22e
Migrated Tibia cog
Galarzaa90 Oct 9, 2018
8864213
Migrated Admin, Core, Info cogs
Galarzaa90 Oct 10, 2018
205c223
Added event migration
Galarzaa90 Oct 10, 2018
a7e0c40
Converted most of event subcommands to postgresql
Galarzaa90 Oct 11, 2018
a514deb
Migrated General cog to postgresql
Galarzaa90 Oct 11, 2018
0e5e26f
Migrated Mod, Owner and Roles cog to postgresql
Galarzaa90 Oct 12, 2018
0824f73
Moved Tracking cog to postgresql
Galarzaa90 Oct 12, 2018
e345dcf
Merge branch 'dev' into feat-postgresql
Galarzaa90 Oct 13, 2018
fd48525
Added watchlist entries migration
Galarzaa90 Oct 13, 2018
c4b0f9a
Removed all references to the old sqlite database
Galarzaa90 Oct 13, 2018
a413abf
Fixed some async access functions in TibiaWiki cog
Galarzaa90 Oct 13, 2018
33f96c2
Merge pull request #137 from NabDev/feat-postgresql
Galarzaa90 Oct 13, 2018
6a63c58
Fixed bug with database migration
Galarzaa90 Oct 15, 2018
d93260b
Improved error handling when opening postgresql connection
Galarzaa90 Oct 15, 2018
c0f1f65
Last announced tibia.com article is now saved on database
Galarzaa90 Oct 15, 2018
bc2e2b0
Add /charms command, improve /choose
Tschis Oct 15, 2018
283dd0b
Autorole's * rule only applies to character in the same world
Galarzaa90 Oct 16, 2018
be58680
New ServerLog cog.
Galarzaa90 Oct 16, 2018
b809462
Character renames are only announced on relevant servers
Galarzaa90 Oct 16, 2018
0290ef7
Add /charm command and refactor /charms
Tschis Oct 16, 2018
9f0d470
Merge branch 'dev' into feat-add-charms
Tschis Oct 16, 2018
1775914
Added database containing charms
Galarzaa90 Oct 16, 2018
52db5c2
Merge pull request #139 from NabDev/feat-add-charms
Galarzaa90 Oct 16, 2018
986e60f
Moved server log entries to ServerLog cog
Galarzaa90 Oct 17, 2018
cd81df7
Fixed bug with level announcements
Galarzaa90 Oct 17, 2018
9448ce5
World transfers of registered characters are now shown in server log
Galarzaa90 Oct 18, 2018
2084443
Added commandstats command
Galarzaa90 Oct 18, 2018
a77cc70
Moved game task to core Cog
Galarzaa90 Oct 19, 2018
e436100
Added method to get audit log entry
Galarzaa90 Oct 19, 2018
c249324
Bots no longer get a welcome message
Galarzaa90 Oct 19, 2018
46d1b7f
Added character_history table
Galarzaa90 Oct 19, 2018
5496bf1
Added support for multiple watchlists per server
Galarzaa90 Oct 20, 2018
83c000b
Fixed some bugs in watchlists
Galarzaa90 Oct 22, 2018
8353f78
Added server history
Galarzaa90 Oct 22, 2018
7740137
Server log channel can now be configured.
Galarzaa90 Oct 23, 2018
1f3aa5a
Merge remote-tracking branch 'origin/master' into dev
Galarzaa90 Oct 23, 2018
b3ba15f
Update Tibia.com URLs
mathiasbynens Nov 5, 2018
2d821f8
Merge branch 'dev' into update-urls
Galarzaa90 Nov 8, 2018
6bb12a1
Merge pull request #143 from mathiasbynens/update-urls
Galarzaa90 Nov 8, 2018
7f3ec13
Upgraded tibiawiki database to version 2.0.0 (unreleased)
Galarzaa90 Nov 15, 2018
2704fe6
Updated bestiary and imbuement commands
Galarzaa90 Nov 16, 2018
907f1e4
Updated item command.
Galarzaa90 Nov 16, 2018
71f35cc
Updated npc command
Galarzaa90 Nov 17, 2018
e320b2d
Updated spell command
Galarzaa90 Nov 17, 2018
94f2ca0
spell command now shows spell effect
Galarzaa90 Nov 19, 2018
8b91e6b
Updated key search command
Galarzaa90 Nov 20, 2018
9a7b6e7
Merge branch 'master' into dev
Galarzaa90 Nov 20, 2018
c3f2255
Updated loot cog
Galarzaa90 Nov 20, 2018
03d9974
Moved server timezones to their own table
Galarzaa90 Nov 21, 2018
234a912
Merged /charms and /charm
Galarzaa90 Nov 21, 2018
eb2eb74
Changed logging system
Galarzaa90 Nov 22, 2018
ba6487f
/stamina command now accepts target stamina
Galarzaa90 Nov 22, 2018
1931c89
Added debug option to see debug log messages
Galarzaa90 Nov 22, 2018
dedd807
Added melee skill training calculator
Galarzaa90 Nov 23, 2018
8d2e03f
Added magic level calculator
Galarzaa90 Nov 23, 2018
7a958dd
Added exercise weapons to skills and ml calculator
Galarzaa90 Nov 23, 2018
ce095f1
Moved stamina, bless and stats to Calculator cog
Galarzaa90 Nov 24, 2018
f274317
Minor style changes
Galarzaa90 Nov 27, 2018
b3d49bc
Added reminder cogs and /remindme command
Galarzaa90 Nov 27, 2018
7e386ca
Added boss timers feature
Galarzaa90 Nov 30, 2018
145b94d
Added 'empty' launcher subcommand
Galarzaa90 Dec 1, 2018
77f2847
Fixed database migration
Galarzaa90 Dec 1, 2018
c5c711f
Add new message for wave shooters
Tschis Dec 4, 2018
51bb3d3
Added HumanDelta class
Galarzaa90 Dec 4, 2018
8e648df
Add new message for life drainers
Tschis Dec 4, 2018
17c7afd
Improve organization of levels messages
Tschis Dec 6, 2018
50163fc
Improve organization of deaths messages
Tschis Dec 6, 2018
a7854a5
Fix some changes and add more grouping for death messages
Tschis Dec 6, 2018
7cc0b7e
Merge pull request #147 from NabDev/feat-new-messages
Galarzaa90 Dec 10, 2018
5e1d65f
Add constant list of wave monsters
Tschis Dec 10, 2018
846b5f1
Merge pull request #148 from NabDev/feat-improve-messages
Galarzaa90 Dec 12, 2018
98315ea
Fix death/level logging that does not end up announcing
Tschis Dec 16, 2018
f080df0
Change loggings to detection instead of announcement
Tschis Dec 16, 2018
6621549
Fix logging when death is too old
Tschis Dec 17, 2018
71cea74
Merge pull request #149 from NabDev/fix-lvldeath-announce
Galarzaa90 Dec 20, 2018
17e0dc3
Implemented Tibia.py
Galarzaa90 Dec 20, 2018
62189e9
Updated some command to work with Tibia.py
Galarzaa90 Dec 21, 2018
23b403f
Reenabled death and level up announcements
Galarzaa90 Dec 21, 2018
94df1cd
Fixed level up announcements
Galarzaa90 Dec 22, 2018
1f13e21
Improved logging
Galarzaa90 Dec 23, 2018
1a58f72
Merge pull request #150 from NabDev/feat-tibiapy
Galarzaa90 Dec 23, 2018
644f351
Updated tibia.py requirement with PyPi version
Galarzaa90 Dec 23, 2018
d29e868
Added DbChar to /levels and /online
Galarzaa90 Dec 23, 2018
a3928a9
Added DbChar to /whois
Galarzaa90 Dec 24, 2018
89fd648
/whois now shows account status and position
Galarzaa90 Dec 24, 2018
906e115
Added DbLevelUp class
Galarzaa90 Dec 24, 2018
9ade4fe
/levels now obtains level ups without queries
Galarzaa90 Dec 26, 2018
5e8093d
Migrating is now 200 times faster but it has some caveats
Galarzaa90 Dec 26, 2018
1d524e5
Removed 'empty' as standalone cli subcommand
Galarzaa90 Dec 27, 2018
8e0fb55
All migration is done using copy_to_tables
Galarzaa90 Dec 27, 2018
945e1cd
Merge pull request #151 from NabDev/feat-better-migration
Galarzaa90 Dec 27, 2018
ac01ea8
Death assists are now saved in the database
Galarzaa90 Dec 27, 2018
30d201c
Replaced queries in /deaths command
Galarzaa90 Dec 28, 2018
4dcb502
Character transfers were being registered as name changes
Galarzaa90 Dec 28, 2018
29f59bd
/deaths user now uses DbDeath class
Galarzaa90 Dec 28, 2018
a5c9cf6
/deaths monster now uses DbDeath class
Galarzaa90 Dec 28, 2018
9a106bf
/timeline and subcommands do not use queries directly anymore
Galarzaa90 Dec 28, 2018
44ac51f
/searchteam now uses DbChar class instead of queries
Galarzaa90 Dec 28, 2018
43378f1
Moved error classes to their own file
Galarzaa90 Dec 29, 2018
b2fbebb
Improving character registering
Galarzaa90 Jan 3, 2019
2a9a5cc
Moved all character tracking commands from Admin cog to Tracking cog
Galarzaa90 Jan 3, 2019
e1e4c55
Added process_character_assignment function
Galarzaa90 Jan 4, 2019
3136a52
Added get_exp database function
Galarzaa90 Jan 4, 2019
30a3bef
Merge pull request #152 from NabDev/feat-improve-registering
Galarzaa90 Jan 4, 2019
ccf0a46
Renamed command checks for better readability
Galarzaa90 Jan 4, 2019
f12c243
Miscellaneous improvements and cleanup
Galarzaa90 Jan 5, 2019
10ba756
get_highscores_tibiadata now uses tibia.py parsing
Galarzaa90 Jan 8, 2019
5ff6866
scan_highscores_task now uses tibiadata highscores
Galarzaa90 Jan 9, 2019
2dc6a16
Added experience functions
Galarzaa90 Jan 9, 2019
e01c4bd
Added /highscores global command
Galarzaa90 Jan 9, 2019
c94eea5
Finished /highscores global command
Galarzaa90 Jan 9, 2019
37d5986
Improved the display of character's highscores
Galarzaa90 Jan 9, 2019
1ab1bb9
Merge pull request #153 from NabDev/dev-highscores
Galarzaa90 Jan 9, 2019
9d0da5c
Most network errors are now handled in on_command_error
Galarzaa90 Jan 9, 2019
48e4b6f
Added Condition class and subclasses for message picking
Galarzaa90 Jan 10, 2019
189f140
Sort watchlist characters by vocation asc and level desc
Tschis Jan 10, 2019
5172ea5
Merge branch 'dev' into feat-order-watchlist
Tschis Jan 10, 2019
0a14da9
Changed display of /stats command
Galarzaa90 Jan 10, 2019
659b0f3
Moved event command and subcommands to timers cog
Galarzaa90 Jan 10, 2019
e4bdf07
Added Event class to handle database events.
Galarzaa90 Jan 11, 2019
1f1b436
/event and /event add now use Event class
Galarzaa90 Jan 11, 2019
4b302ef
/event edit joinable now uses Event class
Galarzaa90 Jan 11, 2019
95ded88
All event subcommands use the new Event class
Galarzaa90 Jan 11, 2019
8c6902b
Replaced event notification task
Galarzaa90 Jan 12, 2019
9191fce
Refactor watchlist scan
Tschis Jan 12, 2019
cc080dd
Merge branch 'dev' into feat-order-watchlist
Tschis Jan 12, 2019
62f9942
Added --quiet option for cleaner console output
Galarzaa90 Jan 12, 2019
959c926
Merge pull request #154 from NabDev/feat-order-watchlist
Galarzaa90 Jan 12, 2019
cbc97a9
Improvements to events
Galarzaa90 Jan 12, 2019
7ef0496
Increased command timeout for migrate
Galarzaa90 Jan 13, 2019
42e0e8c
Fixed bugs with /rashid and /time
Galarzaa90 Jan 13, 2019
b5e56d8
Renamed utils.time to utils.timing
Galarzaa90 Jan 14, 2019
db9a765
Improved calculators usage string
Galarzaa90 Jan 14, 2019
c78ff46
Fixed bug in /searchworld
Galarzaa90 Jan 14, 2019
910dec4
Fixed bug in boss set
Galarzaa90 Jan 14, 2019
1403400
Fixed bugs in calculator commands
Galarzaa90 Jan 14, 2019
de3e548
Fixed bug in sql command related to time module
Galarzaa90 Jan 14, 2019
5d00375
Updated TibiaWiki database to use v2.0.2
Galarzaa90 Jan 14, 2019
ce09042
Replaced character queries in boss timers with DbChar
Galarzaa90 Jan 14, 2019
895f097
Fixed bug in /spells
Galarzaa90 Jan 14, 2019
cb47cfc
PEP8 fixes
Galarzaa90 Jan 14, 2019
3768782
Added database columns to Watchlist class
Galarzaa90 Jan 15, 2019
920f649
Added more methods for Watchlist and WatchlistEntry
Galarzaa90 Jan 15, 2019
287c92d
Watchlist changes
Galarzaa90 Jan 15, 2019
d307465
Cleaned up /deaths command
Galarzaa90 Jan 16, 2019
8cc5fd1
More /death cleanup and other minor changes
Galarzaa90 Jan 16, 2019
e926586
Added some documentation
Galarzaa90 Jan 16, 2019
ea2bfa4
Added adduser subcommand for watchlist
Galarzaa90 Jan 16, 2019
464a72d
Missing await in watchlist task
Galarzaa90 Jan 16, 2019
1f0b8fd
Cleaned up command error handler
Galarzaa90 Jan 16, 2019
125c481
Added command documentation for calculators cog
Galarzaa90 Jan 16, 2019
3cbe01f
Added missing images
Galarzaa90 Jan 16, 2019
60ae9cc
Updated changelog
Galarzaa90 Jan 17, 2019
36195ac
Updated previous changelog entries
Galarzaa90 Jan 17, 2019
96b6f99
Updated changelog
Galarzaa90 Jan 17, 2019
c1788f1
General cog documentation
Galarzaa90 Jan 17, 2019
d70a870
Moved info command images to info subfolder
Galarzaa90 Jan 17, 2019
db15652
/ignore now accepts both channels and users
Galarzaa90 Jan 18, 2019
194a2c7
Finished mod cog documentation
Galarzaa90 Jan 18, 2019
0c6c9cb
Updated owner, roles and half of tibia cogs documentation
Galarzaa90 Jan 18, 2019
1db72cf
/achievement now uses new spoiler feature
Galarzaa90 Jan 18, 2019
9c18369
Added missing image
Galarzaa90 Jan 19, 2019
c9fbddf
Updated TibiaWiki documentation
Galarzaa90 Jan 19, 2019
ca66289
Merge remote-tracking branch 'origin/dev' into dev
Galarzaa90 Jan 19, 2019
b9a5b4d
Added missing tibiawiki images
Galarzaa90 Jan 19, 2019
5c8245b
Added images for boss command and subcommands
Galarzaa90 Jan 20, 2019
e9b554b
Finished command documentation
Galarzaa90 Jan 20, 2019
aa9243f
Updated install instructions
Galarzaa90 Jan 20, 2019
624f453
Added remindme response
Galarzaa90 Jan 20, 2019
38c5e6b
Fixed bug when using extra commas in boss subcommands
Galarzaa90 Jan 21, 2019
ee4aa0e
Typos and errors
Galarzaa90 Jan 21, 2019
38a31ad
Automatic renaming should handle conflicts
Galarzaa90 Jan 21, 2019
d5be586
Optimized images
Galarzaa90 Jan 21, 2019
2235923
Cleanup
Galarzaa90 Jan 21, 2019
f9d8106
Watchlist entries can only be check if the user can see the channel
Galarzaa90 Jan 22, 2019
ee54f67
Documentation fixes
Galarzaa90 Jan 22, 2019
eb69fd4
Minor documentation fixes
Galarzaa90 Jan 22, 2019
84f335d
Merge branch 'master' into dev
Galarzaa90 Jan 22, 2019
8f1ee18
Upgraded tibia.py dependency to fix bug with character urls
Galarzaa90 Jan 22, 2019
e1b9871
Fixed issues with ignore check
Galarzaa90 Jan 23, 2019
e253ca8
Fixed /quote not showing messages with attachments but no content
Galarzaa90 Jan 23, 2019
286b30f
Updated TibiaWiki database
Galarzaa90 Jan 24, 2019
9466f90
Anyone with permissions to see a watchlist can check its lists
Galarzaa90 Jan 24, 2019
bb05c51
Merge remote-tracking branch 'origin/dev' into dev
Galarzaa90 Jan 24, 2019
3a3b7c6
Bumped version
Galarzaa90 Jan 24, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
.vscode
__pycache__

*.db-journal

logs/
loot/
token.txt
postgresql.txt

/data/*
!/data/loot.db
!/data/tibia_database.db
!/data/tibiawiki.db
!/data/tibia_worlds.json
!/data/config_template.yml
/config.yml
Expand All @@ -26,4 +25,5 @@ site/


# Virtual Environments
venv/
venv/

1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ script:
- python -m compileall ./nabbot.py
- python -m compileall ./restart.py
- python -m compileall ./cogs
- python -m compileall ./utils
- cp CHANGELOG.md docs/changelog.md
- python -m mkdocs build
- echo 'docs.nabbot.xyz' > ./site/CNAME
Expand Down
408 changes: 237 additions & 171 deletions CHANGELOG.md

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# NabBot
Nab Bot is a discord bot that uses [Rapptz's discord.py](https://github.com/Rapptz/discord.py). It features commands related to the MMORPG [Tibia](http://www.tibia.com/news/?subtopic=latestnews).
NabBot is a discord bot that uses [Rapptz's discord.py](https://github.com/Rapptz/discord.py). It features commands related to the MMORPG [Tibia](http://www.tibia.com/news/?subtopic=latestnews).

![Python version](https://img.shields.io/badge/python-3.6-yellow.svg)
[![Build Status](https://travis-ci.org/Galarzaa90/NabBot.svg)](https://travis-ci.org/Galarzaa90/NabBot)
[![GitHub release](https://img.shields.io/github/release/Galarzaa90/NabBot.svg)](https://github.com/Galarzaa90/NabBot/releases)
![Python version](https://img.shields.io/badge/python-3.6+-yellow.svg)
[![Build Status](https://travis-ci.org/NabDev/NabBot.svg)](https://travis-ci.org/NabDev/NabBot)
[![GitHub release](https://img.shields.io/github/release/NabDev/NabBot.svg)](https://github.com/NabDev/NabBot/releases)
[![Discord](https://img.shields.io/discord/441991938200305674.svg)](https://discord.gg/NmDvhpY)

[![Discord Bots](https://discordbots.org/api/widget/178966653982212096.svg)](https://discordbots.org/bot/178966653982212096)
Expand All @@ -22,7 +22,12 @@ You can also host your own instance of NabBot.
- pillow
- BeautifulSoup
- pyYAML
- asyncpg
- pytz
- tibia.py
- tibiawiki-sql
- git
- PostgreSQL 10 or higher

### Installing and running
Follow the [install guide](https://nabdev.github.io/NabBot/install/) on the official documentation site.
Expand Down
864 changes: 566 additions & 298 deletions cogs/admin.py

Large diffs are not rendered by default.

396 changes: 396 additions & 0 deletions cogs/calculators.py

Large diffs are not rendered by default.

464 changes: 193 additions & 271 deletions cogs/core.py

Large diffs are not rendered by default.

1,050 changes: 25 additions & 1,025 deletions cogs/general.py

Large diffs are not rendered by default.

260 changes: 149 additions & 111 deletions cogs/info.py

Large diffs are not rendered by default.

1,785 changes: 809 additions & 976 deletions cogs/loot.py

Large diffs are not rendered by default.

227 changes: 134 additions & 93 deletions cogs/mod.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,73 @@
import asyncio
from contextlib import closing
from typing import List, Dict
import logging
from typing import Union

import discord
from discord.ext import commands

from cogs.utils import converter
from nabbot import NabBot
from .utils import checks, config
from .utils import checks, config, safe_delete_message
from .utils.context import NabCtx
from .utils.database import userDatabase, get_server_property
from .utils.pages import Pages, CannotPaginate
from .utils.database import get_server_property
from .utils.errors import CannotPaginate
from .utils.pages import Pages

log = logging.getLogger("nabbot")


class LazyEntry:
__slots__ = ('entity_id', 'guild', '_cache')

def __init__(self, guild, entity_id):
self.entity_id = entity_id
self.guild = guild
self._cache = None

def __str__(self):
if self._cache:
return self._cache

e = self.entity_id
g = self.guild
resolved = g.get_channel(e) or g.get_member(e)
if resolved is None:
self._cache = f'<Not Found: {e}>'
else:
self._cache = resolved.mention
return self._cache


class Mod:
"""Commands server moderators."""
"""Moderating related commands."""
def __init__(self, bot: NabBot):
self.bot = bot
self.ignored = {}
self.reload_ignored()

def __global_check(self, ctx: NabCtx):
return ctx.is_private or ctx.channel.id not in self.ignored.get(ctx.guild.id, []) or checks.is_owner_check(ctx) \
or checks.check_guild_permissions(ctx, {'manage_channels': True})
async def __global_check_once(self, ctx: NabCtx):
"""Checks if the current channel or user is ignored.

# Commands
Bot owners and guild managers can bypass this.
"""
if ctx.guild is None:
return True
if await checks.is_owner(ctx):
return True
if ctx.author_permissions.manage_guild:
return True

return not await self.is_ignored(ctx.pool, ctx)

# region Commands
@commands.guild_only()
@checks.is_channel_mod()
@checks.channel_mod_only()
@commands.command()
async def cleanup(self, ctx: NabCtx, limit: int=50):
async def cleanup(self, ctx: NabCtx, limit: int = 50):
"""Cleans the channel from bot commands.

If the bot has `Manage Messages` permission, it will also delete command invocation messages."""
count = 0
prefixes = get_server_property(ctx.guild.id, "prefixes", deserialize=True, default=config.command_prefix)
# Also skip death and levelup messages from cleanup
prefixes = await get_server_property(ctx.pool, ctx.guild.id, "prefixes", default=config.command_prefix)
# Also skip death and level up messages from cleanup
announce_prefix = (config.levelup_emoji, config.death_emoji, config.pvpdeath_emoji)
if ctx.bot_permissions.manage_messages:
def check(m: discord.Message):
Expand All @@ -51,50 +85,59 @@ def check(m: discord.Message):
if not count:
return await ctx.send("There are no messages to clean.", delete_after=10)

await ctx.send(f"{ctx.tick()} Deleted {count:,} messages.", delete_after=20)
await ctx.success(f"Deleted {count:,} messages.", delete_after=20)

@commands.guild_only()
@checks.is_channel_mod()
@checks.server_mod_only()
@commands.group(invoke_without_command=True, case_insensitive=True)
async def ignore(self, ctx: NabCtx, *, channel: discord.TextChannel = None):
"""Makes the bot ignore a channel.

Ignored channels don't process commands. However, the bot may still announce deaths and level ups if needed.
async def ignore(self, ctx: NabCtx, *entries: converter.ChannelOrMember):
"""Makes the bot ignore a channel or user.

If the command is used with no parameters, it ignores the current channel.
Commands cannot be used in ignored channels or by ignored users.

Note that server administrators can bypass this."""
if channel is None:
channel = ctx.channel
The command accepts a list of names, ids or mentions of users or channels.
If the command is used with no parameters, it ignores the current channel.

if channel.id in self.ignored.get(ctx.guild.id, []):
await ctx.send(f"{channel.mention} is already ignored.")
return

with userDatabase:
userDatabase.execute("INSERT INTO ignored_channels(server_id, channel_id) VALUES(?, ?)",
(ctx.guild.id, channel.id))
await ctx.send(f"{channel.mention} is now ignored.")
self.reload_ignored()
Ignores are bypassed by users with the `Manage Server` permission."""
if len(entries) == 0:
entries = [ctx.channel]
if len(entries) == 1:
entry: Union[discord.Member, discord.TextChannel] = entries[0]
query = "INSERT INTO ignored_entry(server_id, entry_id) VALUES($1, $2) ON CONFLICT DO NOTHING RETURNING 1"
ret = await ctx.pool.fetchval(query, ctx.guild.id, entry.id)
rep = entry.mention if isinstance(entry, discord.TextChannel) else entry.display_name
if ret:
return await ctx.success(f"I'm now ignoring **{rep}**")
return await ctx.error(f"{rep} is already ignored.")

inserted = await self.bulk_ignore(ctx, entries)
if inserted:
if inserted != len(entries):
await ctx.success(f"{inserted} entries are now ignored. The rest was already ignored.")
else:
await ctx.success(f"All {inserted} entries are now ignored.")
else:
await ctx.error("No entries were ignored. They were all already ignored.")

@commands.guild_only()
@checks.is_channel_mod()
@checks.server_mod_only()
@ignore.command(name="list")
async def ignore_list(self, ctx: NabCtx):
"""Shows a list of ignored channels."""
entries = [ctx.guild.get_channel(c).name for c in self.ignored.get(ctx.guild.id, []) if ctx.guild.get_channel(c) is not None]
"""Shows a list of ignored channels and users."""
query = "SELECT entry_id FROM ignored_entry WHERE server_id = $1"
rows = await ctx.pool.fetch(query, ctx.guild.id)

entries = [LazyEntry(ctx.guild, e[0]) for e in rows]
if not entries:
await ctx.send("There are no ignored channels in this server.")
await ctx.send("There are no ignored entries in this server.")
return
pages = Pages(ctx, entries=entries)
pages.embed.title = "Ignored channels"
pages.embed.title = "Ignored entries"
try:
await pages.paginate()
except CannotPaginate as e:
await ctx.send(e)

@commands.command()
@checks.is_channel_mod_somewhere()
@checks.channel_mod_somewhere()
async def makesay(self, ctx: NabCtx, *, message: str):
"""Makes the bot say a message.

Expand Down Expand Up @@ -159,35 +202,35 @@ def check(m):
return await ctx.send(f"{ctx.tick(False)} I need `Manage Messages` permission to use this command.")
if not ctx.author_permissions.manage_channels:
return await ctx.send(f"{ctx.tick(False)} You need `Manage Channel` permission to use this command.")
await safe_delete_message(ctx.message)
await ctx.message.delete()
await ctx.channel.send(message)

@commands.guild_only()
@checks.is_channel_mod()
@checks.channel_mod_only()
@commands.command()
async def unignore(self, ctx: NabCtx, *, channel: discord.TextChannel = None):
"""Unignores a channel.

If no channel is provided, the current channel will be unignored.
async def unignore(self, ctx: NabCtx, *entries: converter.ChannelOrMember):
"""Removes a channel or user from the ignored list.

Ignored channels don't process commands. However, the bot may still announce deaths and level ups if needed.
If no parameter is provided, the current channel will be unignored.

If the command is used with no parameters, it unignores the current channel."""
if channel is None:
channel = ctx.channel

if channel.id not in self.ignored.get(ctx.guild.id, []):
await ctx.send(f"{channel.mention} is not ignored.")
return

with userDatabase:
userDatabase.execute("DELETE FROM ignored_channels WHERE channel_id = ?", (channel.id,))
await ctx.send(f"{channel.mention} is not ignored anymore.")
self.reload_ignored()

@checks.is_channel_mod()
@commands.guild_only()
@checks.is_tracking_world()
if len(entries) == 0:
query = "DELETE FROM ignored_entry WHERE server_id=$1 AND entry_id=$2 RETURNING true"
res = await ctx.pool.fetchval(query, ctx.guild.id, ctx.channel.id)
if res:
return await ctx.success(f"{ctx.channel.mention} is no longer ignored.")
return await ctx.error(f"{ctx.channel.mention} wasn't ignored.")
query = "DELETE FROM ignored_entry WHERE server_id=$1 AND entry_id = ANY($2::bigint[]) RETURNING entry_id"
# noinspection PyUnresolvedReferences
entries = [c.id for c in entries]
rows = await ctx.pool.fetch(query, ctx.guild.id, entries)
if rows:
return await ctx.success(f"{len(rows)} are now unignored.")
await ctx.error("No entries were unignored.")

@checks.channel_mod_only()
@checks.tracking_world_only()
@commands.command()
async def unregistered(self, ctx: NabCtx):
"""Shows a list of users with no registered characters."""
Expand All @@ -196,13 +239,9 @@ async def unregistered(self, ctx: NabCtx):
await ctx.send("This server is not tracking any worlds.")
return

with closing(userDatabase.cursor()) as c:
c.execute("SELECT user_id FROM chars WHERE world LIKE ? GROUP BY user_id", (ctx.world,))
result = c.fetchall()
if len(result) <= 0:
await ctx.send("There are no unregistered users.")
return
users = [i["user_id"] for i in result]
results = await ctx.pool.fetch('SELECT user_id FROM "character" WHERE world = $1 GROUP BY user_id', ctx.world)
# Flatten list
users = [i["user_id"] for i in results]
for member in ctx.guild.members: # type: discord.Member
# Skip bots
if member.bot:
Expand All @@ -219,28 +258,30 @@ async def unregistered(self, ctx: NabCtx):
await pages.paginate()
except CannotPaginate as e:
await ctx.send(e)

def reload_ignored(self):
"""Refresh the world list from the database

This is used to avoid reading the database every time the world list is needed.
A global variable holding the world list is loaded on startup and refreshed only when worlds are modified"""
c = userDatabase.cursor()
ignored_dict_temp: Dict[int, List[int]] = {}
try:
c.execute("SELECT server_id, channel_id FROM ignored_channels")
result: Dict = c.fetchall()
if len(result) > 0:
for row in result:
if not ignored_dict_temp.get(row["server_id"]):
ignored_dict_temp[row["server_id"]] = []

ignored_dict_temp[row["server_id"]].append(row["channel_id"])

self.ignored.clear()
self.ignored.update(ignored_dict_temp)
finally:
c.close()
# endregion

@classmethod
async def is_ignored(cls, conn, ctx: NabCtx):
"""Checks if the current context is ignored.

A context could be ignored because either the channel or the user are in the ignored list."""
query = "SELECT True FROM ignored_entry WHERE server_id=$1 AND (entry_id=$2 OR entry_id=$3);"
return await conn.fetchrow(query, ctx.guild.id, ctx.channel.id, ctx.author.id)

@classmethod
async def bulk_ignore(cls, ctx: NabCtx, entries):
async with ctx.pool.acquire() as conn:
async with conn.transaction():
query = "SELECT entry_id FROM ignored_entry WHERE server_id=$1;"
records = await conn.fetch(query, ctx.guild.id)

# Removing duplicates
current_entries = {r[0] for r in records}
records = [(ctx.guild.id, e.id) for e in entries if e.id not in current_entries]

# do a bulk COPY
await conn.copy_records_to_table('ignored_entry', columns=['server_id', 'entry_id'], records=records)
return len(records)


def setup(bot):
Expand Down
Loading