diff --git a/Pipfile b/Pipfile index 1ddd47f..ee47af4 100644 --- a/Pipfile +++ b/Pipfile @@ -6,6 +6,7 @@ name = "pypi" [packages] ts3 = "*" python-dotenv = "*" +pycoingecko = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 134b58f..18d8970 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "af14d89df0cae7c6218bd3ec7d0221c80e477db4b5f94216d877f6d664142f4c" + "sha256": "dea9fe66fc91a3adf33caec6ce10635546f9e81ec613bc3bbba14c257d57029b" }, "pipfile-spec": 6, "requires": { @@ -16,6 +16,37 @@ ] }, "default": { + "certifi": { + "hashes": [ + "sha256:2bbf76fd432960138b3ef6dda3dde0544f27cbf8546c458e60baf371917ba9ee", + "sha256:50b1e4f8446b06f41be7dd6338db18e0990601dce795c2b1686458aa7e8fa7d8" + ], + "version": "==2021.5.30" + }, + "charset-normalizer": { + "hashes": [ + "sha256:5d209c0a931f215cee683b6445e2d77677e7e75e159f78def0db09d68fafcaa6", + "sha256:5ec46d183433dcbd0ab716f2d7f29d8dee50505b3fdb40c6b985c7c4f5a3591f" + ], + "markers": "python_version >= '3'", + "version": "==2.0.6" + }, + "idna": { + "hashes": [ + "sha256:14475042e284991034cb48e06f6851428fb14c4dc953acd9be9a5e95c7b6dd7a", + "sha256:467fbad99067910785144ce333826c71fb0e63a425657295239737f7ecd125f3" + ], + "markers": "python_version >= '3'", + "version": "==3.2" + }, + "pycoingecko": { + "hashes": [ + "sha256:3646968c8c6936ca4e94b5f562328a763c12a0e9644141cb0215089dda59fe01", + "sha256:9add73085729b1f10f93c7948490b09e8cd47c29bebe47dccb319e8b49502d0c" + ], + "index": "pypi", + "version": "==2.2.0" + }, "python-dotenv": { "hashes": [ "sha256:aae25dc1ebe97c420f50b81fb0e5c949659af713f31fdb63c749ca68748f34b1", @@ -24,6 +55,14 @@ "index": "pypi", "version": "==0.19.0" }, + "requests": { + "hashes": [ + "sha256:6c1246513ecd5ecd4528a0906f910e8f0f9c6b8ec72030dc9fd154dc1a6efd24", + "sha256:b8aa58f8cf793ffd8782d3d8cb19e66ef36f7aba4353eec859e74678b01b07a7" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", + "version": "==2.26.0" + }, "ts3": { "hashes": [ "sha256:5c7ddee40f4446d4b6c541665cc536d270481f82c27adfe1c2e371426ddbd0d7", @@ -31,6 +70,14 @@ ], "index": "pypi", "version": "==1.0.11" + }, + "urllib3": { + "hashes": [ + "sha256:4987c65554f7a2dbf30c18fd48778ef124af6fab771a377103da0585e2336ece", + "sha256:c4fdf4019605b6e5423637e01bc9fe4daef873709a7973e195ceba0a62bbc844" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'", + "version": "==1.26.7" } }, "develop": {} diff --git a/gecko.py b/gecko.py new file mode 100644 index 0000000..df14884 --- /dev/null +++ b/gecko.py @@ -0,0 +1,58 @@ +""" +TBD +""" + +__author__ = "Lukas Mahler" +__version__ = "0.0.1" +__date__ = "23.09.2021" +__email__ = "m@hler.eu" +__status__ = "Development" + +# Imports +from pycoingecko import CoinGeckoAPI + + +class GeckoAPI: + + def __init__(self): + self.api = self.getAPI() + self.coinlist = self.getCoins() + + @staticmethod + def getAPI(): + """ + + """ + + api = CoinGeckoAPI() + if api.ping()['gecko_says'] == '(V3) To the Moon!': + return api + else: + raise ConnectionError("Couldnt connect to Coingecko API.") + + def getCoins(self): + """ + + """ + + return self.api.get_coins_list() + + def getSymbol(self, symbol, curr="EUR", decimal=2): + """ + + """ + + matching = [x for x in self.coinlist if x["symbol"] == symbol.lower()] + if len(matching) == 1: + resp_dict = self.api.get_price(ids=matching[0]["id"], vs_currencies=curr.lower()) + price = resp_dict[matching[0]["id"]][curr.lower()] + if isinstance(price, int): + price = float(price) # Convert to always have floats + price = f"{price:.{decimal}f}" + return price + else: + return "No unique coin found" + + +if __name__ == "__main__": + exit() diff --git a/myTS3.py b/myTS3.py index e4e2b18..dc0916c 100644 --- a/myTS3.py +++ b/myTS3.py @@ -16,6 +16,7 @@ from time import sleep # Custom import ts3 import dotenv # python-dotenv +import gecko class MyTeamspeakBot: @@ -32,6 +33,7 @@ class MyTeamspeakBot: self.sid = conf["sid"] self.nickname = conf["name"] + self.gecko = gecko.GeckoAPI() self.myid = None self.running = True self.intro = "" @@ -73,6 +75,9 @@ class MyTeamspeakBot: # Subscribe to chat channel messages self.bot.servernotifyregister(event="textchannel") + + # Subscribe to server channel messages + self.bot.servernotifyregister(event="textserver") # Subscribe to channel movement events # self.bot.servernotifyregister(event="channel", id_=0) @@ -281,58 +286,66 @@ class MyTeamspeakBot: """ - if msg.startswith("!"): + if msg.startswith("."): commandstring = msg.split(" ") command = commandstring[0] parameter = commandstring[1:] print(f"* command: {command} / parameter: {parameter} / invkr_id: {invkr_id}") - if command == "!annoy": + if command == ".annoy": try: target = parameter[0] msg = parameter[1] self.poke(msg=msg, usr=target) except IndexError: - err = "Please use the command like this: !annoy TARGET MESSAGE" + err = "Please use the command like this: .annoy TARGET MESSAGE" self.bot.sendtextmessage(targetmode=1, target=invkr_id, msg=err) pass - elif command == "!kickall": + elif command == ".kickall": self.kickall("test") # TODO - elif command == "!test": + elif command == ".test": cid = self.createChannel("Test") self.bot.sendtextmessage(targetmode=1, target=invkr_id, msg=cid) - elif command == "!btc": - self.editChannelname(200, f"[cspacerBTC]Bitcoin: {50000}€") # TODO + elif command == ".btc": + channelname = f"{'[cspacerBTC]Bitcoin:':<33}" + f"{self.gecko.getSymbol('BTC', decimal=0):>5}€" + try: + self.editChannelname(200, channelname) + except ts3.query.TS3QueryError: + pass - elif command == "!eth": - self.editChannelname(201, f"[cspacerETH]Ethereum: {3000}€") # TODO + elif command == ".eth": + channelname = f"{'[cspacerETH]Ethereum:':<30}" + f"{self.gecko.getSymbol('ETH', decimal=0):>5}€" + try: + self.editChannelname(201, channelname) + except ts3.query.TS3QueryError: + pass - elif command == "!list": + elif command == ".list": try: self.list(parameter[0], invkr_id) except IndexError: - err = "Please use the command like this: !list channel/clients" + err = "Please use the command like this: .list channel/clients" self.bot.sendtextmessage(targetmode=1, target=invkr_id, msg=err) pass - elif command == "!follow": + elif command == ".follow": pass # TODO - elif command == "!rename": + elif command == ".rename": pass # TODO - elif command == "!stop" or command == "!quit" or command == "!q": + elif command == ".stop" or command == ".quit" or command == ".q": self.stop(invkr_id) - elif command == "!pingall": + elif command == ".pingall": try: msg = parameter[0] self.poke(msg=msg) except IndexError: - err = "Please use the command like this: !pingall MESSAGE" + err = "Please use the command like this: .pingall MESSAGE" self.bot.sendtextmessage(targetmode=1, target=invkr_id, msg=err) pass