summaryrefslogtreecommitdiffstats
path: root/common/strings.py
blob: 6941a6bd60d953bb9f3360a5340dca35680cb1a1 (plain)
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
# -*- coding: utf-8 -*-
from random import choice
import json


class StaticAnswers:
	"""
	collection of callable static/ semi-static strings
	"""
	def __init__(self):
		with open("./common/strings.json") as basefile:
			self.strings = json.load(basefile)

		self.helpfile = self.strings["help"]
		self.keywords = self.strings["functions"]["keywords"]
		self.replys = self.strings["functions"]["answers"]

	def keys(self, key=None):
		# if specific keyword in referenced return that
		if key in self.keywords:
			return self.keywords[key]

		# in any other case return the whole dict
		return self.keywords["all"]

	def help_doc(self, key=None):
		# if specific key is referenced return only that key
		if key is not None:
			return self.helpfile["help_advanced"][key]

		# in any other case return basic dict
		return self.helpfile["help_basic"]

	def answers(self, nick=None):
		# return pseudo random answer
		return choice(self.replys) % nick