Add server_mode config option

This commit is contained in:
luk3yx 2020-08-13 19:23:53 +12:00
parent 5aaf1f7ed8
commit 3aa8e9a8eb
2 changed files with 14 additions and 4 deletions

View File

@ -9,3 +9,6 @@ admins = Edgy1, luk3yx
# Optional and case-sensitive (defaults to +v list) # Optional and case-sensitive (defaults to +v list)
# server_list = MinetestServer1, MinetestServer2 # server_list = MinetestServer1, MinetestServer2
# Optional, the mode to use when finding MT servers. Default: v
# server_mode = v

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# #
# trackr 2.2.0 # trackr 2.2.1
# #
# © 2020 by luk3yx. # © 2020 by luk3yx.
# #
@ -33,9 +33,12 @@
# secret = Random string to use when generating passwords # secret = Random string to use when generating passwords
# admins = Edgy1, luk3yx # admins = Edgy1, luk3yx
# #
# # Optional and case-sensitive (defaults to +v list) # # Optional and case-sensitive. If not specified, server_mode is used.
# # server_list = MinetestServer1, MinetestServer2 # # server_list = MinetestServer1, MinetestServer2
# #
# # Optional, the mode to use when finding MT servers. Default: v
# # server_mode = v
#
import hashlib, math, miniirc, miniirc_extras, os, random, sys, time import hashlib, math, miniirc, miniirc_extras, os, random, sys, time
assert miniirc.ver >= (1,4,0), 'Update miniirc.' assert miniirc.ver >= (1,4,0), 'Update miniirc.'
@ -47,7 +50,7 @@ from miniirc_extras.features.users import AbstractChannel, User, UserTracker
from typing import Dict, FrozenSet, List, Optional, Set, Tuple, Union from typing import Dict, FrozenSet, List, Optional, Set, Tuple, Union
__version__ = '2.2.0' __version__ = '2.2.1'
# Errors # Errors
class BotError(Exception): class BotError(Exception):
@ -292,6 +295,10 @@ class Trackr:
if serverlist: if serverlist:
self.server_list = frozenset(map(str.strip, serverlist.split(','))) self.server_list = frozenset(map(str.strip, serverlist.split(',')))
self.server_mode: str = config.get('server_mode', 'v')
if len(self.server_mode) != 1:
err(f'Invalid server mode {self.server_mode!r}.')
kwargs = {} kwargs = {}
for i in 'ident', 'realname', 'ns_identity', 'connect_modes', \ for i in 'ident', 'realname', 'ns_identity', 'connect_modes', \
'quit_message': 'quit_message':
@ -346,7 +353,7 @@ class Trackr:
hostmask = self.users[hostmask] hostmask = self.users[hostmask]
return 'players' in hostmask.keys() return 'players' in hostmask.keys()
modes = self.server_list or channel.modes.getset('v') modes = self.server_list or channel.modes.getset(self.server_mode)
if isinstance(hostmask, User): if isinstance(hostmask, User):
hostmask = hostmask.hostmask hostmask = hostmask.hostmask