From 10612a6cfe227fdf0da3ca181d1015228373f11c Mon Sep 17 00:00:00 2001
From: kefthymic <74056501+kefthymic@users.noreply.github.com>
Date: Thu, 16 Feb 2023 13:35:53 +0200
Subject: [PATCH] Adding the new plugin: basketball (#187)
* Adding the new plugin: basketball
* Editing the fun.rst
* add the basketball plugin in README.md
* Update README.md
* [pre-commit.ci lite] apply automatic fixes
* format README and main.py
---------
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
---
README.md | 16 +-
docs/source/Plugins/fun.rst | 5 +
.../plugins/downloaded/basketball/__init__.py | 0
.../plugins/downloaded/basketball/info.py | 15 ++
.../plugins/downloaded/basketball/main.py | 219 ++++++++++++++++++
src/honeybot/settings/PLUGINS.conf | 1 +
src/honeybot/test_plugin_script.py | 4 +-
7 files changed, 250 insertions(+), 10 deletions(-)
create mode 100644 src/honeybot/plugins/downloaded/basketball/__init__.py
create mode 100644 src/honeybot/plugins/downloaded/basketball/info.py
create mode 100644 src/honeybot/plugins/downloaded/basketball/main.py
diff --git a/README.md b/README.md
index 45a8983..8132fbe 100644
--- a/README.md
+++ b/README.md
@@ -2,9 +2,6 @@
-
-
-
[![PyPI version](https://badge.fury.io/py/honeybot.png)](https://badge.fury.io/py/honeybot)
@@ -15,12 +12,14 @@
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/pyhoneybot/honeybot/badge)](https://api.securityscorecards.dev/projects/github.com/pyhoneybot/honeybot)
## Launching pyhoneybot Rewards
- Contributed to pyhoneybot? Here is a big thank you from our community to you.
- Claim your badge and showcase them with pride.
- Let us inspire more folks !
- ![pyhoneybot Badges](https://aviyel.com/assets/uploads/rewards/share/project/84/512/share.png)
- ### **[Claim Now!](https://aviyel.com/projects/84/pyhoneybot/rewards)**
+Contributed to pyhoneybot? Here is a big thank you from our community to you.
+Claim your badge and showcase them with pride.
+Let us inspire more folks !
+
+![pyhoneybot Badges](https://aviyel.com/assets/uploads/rewards/share/project/84/512/share.png)
+
+### **[Claim Now!](https://aviyel.com/projects/84/pyhoneybot/rewards)**
🇲🇺 🇺🇸 🇨🇦 🇦🇷 🇮🇳 🇬🇧 🇬🇬 🇧🇷 🇸🇽 🇵🇱 🇩🇪 🇲🇼
@@ -133,6 +132,7 @@ GUI clients are used to manage plugins, launch bot as well as specify credential
| 🛢 URL Shortener | Shortens a url | [@rakeshseal0](https://github.com/rakeshseal0) |
| 😁 emoji | Returns emoji meaning | [@deadex-ng](https://github.com/deadex-ng) |
| :birthday: birthday | Shows birthday match probability on a people group. | [@paulosgf](https://github.com/paulosgf) |
+| 🏀 basketball | Shows information about the medals of euroBasket and Basketball world cup | [@kefthymic](https://github.com/kefthymic) |
## ⚡ Quickstart
diff --git a/docs/source/Plugins/fun.rst b/docs/source/Plugins/fun.rst
index 9041ab4..762f88e 100644
--- a/docs/source/Plugins/fun.rst
+++ b/docs/source/Plugins/fun.rst
@@ -36,6 +36,11 @@ Magic 8 Ball
.. automodule:: plugins.downloaded.magic_ball.main
:members:
+Basketball
+^^^^^^^^^^
+.. automodule:: plugins.downloaded.basketball.main
+ :members:
+
Monopoly
^^^^^^^^
TODO
diff --git a/src/honeybot/plugins/downloaded/basketball/__init__.py b/src/honeybot/plugins/downloaded/basketball/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/src/honeybot/plugins/downloaded/basketball/info.py b/src/honeybot/plugins/downloaded/basketball/info.py
new file mode 100644
index 0000000..bb6d197
--- /dev/null
+++ b/src/honeybot/plugins/downloaded/basketball/info.py
@@ -0,0 +1,15 @@
+NAME = "basketball.py"
+
+ORIGINAL_AUTHORS = ["Konstantinos Efthymiadis"]
+
+ABOUT = """
+Given the event and year as parameters, the plugin will return the countries that won the medal that year
+Given the event and country as parameters, the plugin will return the number of medals this country has won
+"""
+
+COMMANDS = """
+>>> .basketball <
> <>
+returns a string with all the information
+>>> .basketball <> <>
+returns a table with all the medals of all the years
+"""
diff --git a/src/honeybot/plugins/downloaded/basketball/main.py b/src/honeybot/plugins/downloaded/basketball/main.py
new file mode 100644
index 0000000..aa5c7f3
--- /dev/null
+++ b/src/honeybot/plugins/downloaded/basketball/main.py
@@ -0,0 +1,219 @@
+"""
+[basketball.py]
+Basketball Plugin
+
+[Author]
+Konstantinos Efthymiadis
+
+[About]
+Given the event and year as parameters, the plugin will return the countries that won the medal that year
+Given the event and country as parameters, the plugin will return the number of medals this country has won
+
+[Commands]
+>>> .basketball <> <>
+returns a string with all the information
+>>> .basketball <> <>
+returns a table with all the medals of all the years
+"""
+
+dataEuroBasket = {
+ "1935": ["Latvia", "Spain", "Czechoslovakia", "24-18"],
+ "1937": ["Lithuania", "Italy", "France", "24-23"],
+ "1939": ["Lithuania", "Latvia", "Poland", "No playOffs"],
+ "1946": ["Czechoslovakia", "Italy", "Hungary", "34-32"],
+ "1947": ["USSR", "Czechoslovakia", "Egypt", "56-37"],
+ "1949": ["Egypt", "France", "Greece", "No playOffs"],
+ "1951": ["USSR", "Czechoslovakia", "France", "45-44"],
+ "1953": ["USSR", "Hungary", "France", "No playOffs"],
+ "1955": ["Hungary", "Czechoslovakia", "USSR", "No playOffs"],
+ "1957": ["USSR", "Bulgaria", "Czechoslovakia", "No playOffs"],
+ "1959": ["USSR", "Czechoslovakia", "France", "No playOffs"],
+ "1961": ["USSR", "Yugoslavia", "Bulgaria", "60-53"],
+ "1963": ["USSR", "Poland", "Yugoslavia", "61-45"],
+ "1965": ["USSR", "Yugoslavia", "Poland", "58-49"],
+ "1967": ["USSR", "Czechoslovakia", "Poland", "89-77"],
+ "1969": ["USSR", "Yugoslavia", "Czechoslovakia", "81-72"],
+ "1971": ["USSR", "Yugoslavia", "Italy", "69-64"],
+ "1973": ["Yugoslavia", "Spain", "USSR", "78-67"],
+ "1975": ["Yugoslavia", "USSR", "Italy", "No playOffs"],
+ "1977": ["Yugoslavia", "USSR", "Czechoslovakia", "74-61"],
+ "1979": ["USSR", "Israel", "Yugoslavia", "98-76"],
+ "1981": ["USSR", "Yugoslavia", "Czechoslovakia", "84-67"],
+ "1983": ["Italy", "Spain", "USSR", "105-96"],
+ "1985": ["USSR", "Czechoslovakia", "Italy", "120-89"],
+ "1987": ["Greece", "USSR", "Yugoslavia", "103-101"],
+ "1989": ["Yugoslavia", "Greece", "USSR", "98-77"],
+ "1991": ["Yugoslavia", "Italy", "Spain", "88-73"],
+ "1993": ["Germany", "Russia", "Croatia", "71-70"],
+ "1995": ["Yugoslavia", "Lithuania", "Croatia", "96-90"],
+ "1997": ["Yugoslavia", "Italy", "Russia", "61-49"],
+ "1999": ["Italy", "Spain", "Yugoslavia", "64-56"],
+ "2001": ["Yugoslavia", "Turkey", "Spain", "78-69"],
+ "2003": ["Lithuania", "Spain", "Italy", "93-84"],
+ "2005": ["Greece", "Germany", "France", "78-62"],
+ "2007": ["Russia", "Spain", "Lithuania", "60-59"],
+ "2009": ["Spain", "Serbia", "Greece", "85-63"],
+ "2011": ["Spain", "France", "Russia", "98-85"],
+ "2013": ["France", "Lithuania", "Spain", "80-66"],
+ "2015": ["Spain", "Lithuania", "France", "80-63"],
+ "2017": ["Slovenia", "Serbia", "Spain", "93-85"],
+ "2022": ["Spain", "France", "Germany", "88-76"],
+}
+dataWorldCup = {
+ "1950": ["Argentina", "USA", "Chile", "64-50"],
+ "1954": ["USA", "Brazil", "Philippines", "62-41"],
+ "1959": ["Brazil", "USA", "Chile", "81-67"],
+ "1963": ["Brazil", "Yugoslavia", "USSR", "90-71"],
+ "1967": ["USSR", "Yugoslavia", "Brazil", "71-59"],
+ "1970": ["Yugoslavia", "Brazil", "USSR", "80-55"],
+ "1974": ["USSR", "Yugoslavia", "USA", "79-82"],
+ "1978": ["Yugoslavia", "USSR", "Brazil", "82-81"],
+ "1982": ["USSR", "USA", "Yugoslavia", "95-94"],
+ "1986": ["USA", "USSR", "Yugoslavia", "87-85"],
+ "1990": ["Yugoslavia", "USSR", "USA", "92-75"],
+ "1994": ["USA", "Russia", "Croatia", "137-91"],
+ "1998": ["Yugoslavia", "Russia", "USA", "64-62"],
+ "2002": ["Yugoslavia", "Argentina", "Germany", "84-77"],
+ "2006": ["Spain", "Greece", "USA", "70-47"],
+ "2010": ["USA", "Turkey", "Lithuania", "81-64"],
+ "2014": ["USA", "Serbia", "France", "129-92"],
+ "2019": ["Spain", "Argentina", "France", "95-75"],
+}
+
+
+class Plugin:
+ def __init__(self):
+ pass
+
+ def __accordingToYear__(year, event):
+ dataEvent = {}
+ if event == "eu":
+ dataEvent = dataEuroBasket
+ elif event == "wc":
+ dataEvent = dataWorldCup
+
+ if year in dataEvent:
+ data = dataEvent.get(year)
+ text = "Gold: " + data[0] + "\nSilver: " + data[1] + "\nBronze: " + data[2]
+ if data[3] != "No playOffs":
+ text += "\nFinal Score:\n" + data[0] + " " + data[3] + " " + data[1]
+ return text
+ else:
+ return "No results for that year"
+
+ def __accordingToCountry__(country, event):
+ dataEvent = {}
+ if event == "eu":
+ dataEvent = dataEuroBasket
+ elif event == "wc":
+ dataEvent = dataWorldCup
+
+ goldMedal = 0
+ silverMedal = 0
+ bronzeMedal = 0
+
+ for value in dataEvent.values():
+ if value[0].upper() == country.upper():
+ goldMedal += 1
+ elif value[1].upper() == country.upper():
+ silverMedal += 1
+ elif value[2].upper() == country.upper():
+ bronzeMedal += 1
+
+ if goldMedal == silverMedal and silverMedal == bronzeMedal and bronzeMedal == 0:
+ return "The country: " + country + " does not have any medal"
+ else:
+ text = (
+ country
+ + " Medals:\n"
+ + "Gold: "
+ + str(goldMedal)
+ + "\nSilver: "
+ + str(silverMedal)
+ + "\nBronze: "
+ + str(bronzeMedal)
+ + "\nTotal Medals: "
+ + str(goldMedal + silverMedal + bronzeMedal)
+ )
+ return text
+
+ def __createTable__(maxLen, word):
+ whiteCharacters = maxLen - len(word)
+ text = ""
+ for i in range(0, whiteCharacters // 2):
+ text += " "
+ text += word
+ for i in range(whiteCharacters // 2, whiteCharacters):
+ text += " "
+ text += "|"
+ return text
+
+ def __allTheMedalsAllTheYears__(event):
+ dataEvent = {}
+ text = ""
+ if event == "eu":
+ dataEvent = dataEuroBasket
+ text = "European Basketball Championship\n"
+ elif event == "wc":
+ dataEvent = dataWorldCup
+ text = "FIBA Basketball World Cup\n"
+
+ if not dataEvent:
+ return
+
+ maxForGold = -1
+ maxForSilver = -1
+ maxForBronze = -1
+
+ for value in dataEvent.values():
+ if len(value[0]) > maxForGold:
+ maxForGold = len(value[0])
+ if len(value[1]) > maxForSilver:
+ maxForSilver = len(value[1])
+ if len(value[2]) > maxForBronze:
+ maxForBronze = len(value[2])
+
+ goldMedal = "Gold Medal"
+ silverMedal = "Silver Medal"
+ bronzeMedal = "Bronze Medal"
+
+ if len(goldMedal) > maxForGold:
+ maxForGold = len(goldMedal)
+ if len(silverMedal) > maxForSilver:
+ maxForSilver = len(silverMedal)
+ if len(bronzeMedal) > maxForBronze:
+ maxForBronze = len(bronzeMedal)
+
+ text += "|Year|"
+ text += Plugin.__createTable__(maxForGold, goldMedal)
+ text += Plugin.__createTable__(maxForSilver, silverMedal)
+ text += Plugin.__createTable__(maxForBronze, bronzeMedal)
+ text += "\n"
+
+ for key in dataEvent.keys():
+ text += "|" + key + "|"
+ temp = dataEvent.get(key)
+
+ text += Plugin.__createTable__(maxForGold, temp[0])
+ text += Plugin.__createTable__(maxForSilver, temp[1])
+ text += Plugin.__createTable__(maxForBronze, temp[2])
+ text += "\n"
+
+ return text
+
+ def run(self, incoming, methods, info, bot_info):
+ try:
+ msgs = info["args"][1:][0].split()
+ if info["command"] == "PRIVMSG" and len(msgs) == 3 and msgs[0] == ".basketball":
+ event = msgs[1]
+ if msgs[2] == "all":
+ methods["send"](info["address"], Plugin.__allTheMedalsAllTheYears__(msgs[1]))
+ elif msgs[2].isnumeric():
+ methods["send"](info["address"], Plugin.__accordingToYear__(msgs[2], msgs[1]))
+ else:
+ methods["send"](
+ info["address"], Plugin.__accordingToCountry__(msgs[2], msgs[1])
+ )
+
+ except Exception as e:
+ print("Something Wrong. There is a Plugin Error: ", e)
diff --git a/src/honeybot/settings/PLUGINS.conf b/src/honeybot/settings/PLUGINS.conf
index ed146a8..5b33ff2 100644
--- a/src/honeybot/settings/PLUGINS.conf
+++ b/src/honeybot/settings/PLUGINS.conf
@@ -2,3 +2,4 @@ help
age
caesar_cipher
greet
+basketball
diff --git a/src/honeybot/test_plugin_script.py b/src/honeybot/test_plugin_script.py
index c36607f..1e6520c 100644
--- a/src/honeybot/test_plugin_script.py
+++ b/src/honeybot/test_plugin_script.py
@@ -2,7 +2,7 @@
↓↓↓↓ """
import time
-from plugins import roman_numeral as test_plugin
+from plugins import basketball as test_plugin
test_plugin = test_plugin.Plugin
@@ -71,7 +71,7 @@ def send_target(self, target, msg):
4.1 User quitting a channel
"""
- incoming_command_test = ".roman 420"
+ incoming_command_test = ".basketball eu all"
Tester("message", incoming_command_test)
# Tester('user_join', incoming_command_test)