/
deutschbot.py
65 lines (53 loc) · 1.84 KB
/
deutschbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import argparse
import sys
import logging
import communitybot.settings
from communitybot.curate import Curator
from communitybot.utils import add_discord_user, get_steem_conn
from communitybot.utils import get_option
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logging.basicConfig()
runners = ["discordbot", "curate"]
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--run")
parser.add_argument("--add-discord-user")
parser.add_argument("--start-block")
args = parser.parse_args()
runner = args.run
start_block = args.start_block
if args.add_discord_user:
added = add_discord_user(*args.add_discord_user.split("#"))
if added:
sys.exit("%s added to the authorized discord users." %
args.add_discord_user)
else:
sys.exit("%s is already an authorized discord user." %
args.add_discord_user)
if runner and runner not in runners:
sys.exit(
"%s is not in available runners. Options: %s" % (
args.run, runners)
)
if runner == "discordbot":
from communitybot.discordbot import bot
bot.run(communitybot.settings.BOT_TOKEN)
elif runner == "curate":
c = Curator(
get_steem_conn(),
communitybot.settings.TAGS,
communitybot.settings.BOT_ACCOUNT,
)
starting_point = None
if start_block:
starting_point = int(start_block)
else:
# get the starting point
option = get_option(communitybot.settings.LAST_BLOCK_ID)
if option:
starting_point = int(option["value"])
logger.info("Starting from block %s", starting_point)
c.listen_blocks(starting_point=starting_point)
if __name__ == '__main__':
main()