Skip to content

Commit

Permalink
Started factoring out code to add a telegram bot
Browse files Browse the repository at this point in the history
  • Loading branch information
jgkaplan committed Jul 31, 2022
1 parent cbd8710 commit 553402b
Show file tree
Hide file tree
Showing 95 changed files with 164 additions and 12 deletions.
33 changes: 33 additions & 0 deletions PRIVACY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Privacy Policy
Last Updated: Jul 28, 2022
By using our Bot, you agree that you have read and agree to this policy.

This is our "Privacy Policy" which sets out the policy which governs our use of information you provide in connection with the simple tarot bot. The terms "you" and "your" refer to all individuals or entities accessing this website. The terms "we," "us," "our," refer to the creators of Simple Tarot Bot and "bot" refers to our Discord bot itself.

We may update this Privacy Policy from time to time. Changes in our Privacy Policy will be effective immediately. If you are a regular user of the bot, we recommend that you check this Privacy Policy on a regular basis. By using the bot, you consent to the collection, use and transfer of your information in accordance with this Privacy Policy. If you do not agree to this Privacy Policy, please do not use our bot.

PRIVACY STATEMENT
We respect the privacy of your information. We provide this explanation about our information practices as a show of our commitment to protect your privacy. This policy describes the types of information we may collect from you or that you may provide when you visit this website and our practices for collecting, using, maintaining, protecting and disclosing that information.

Please read this policy carefully to understand our policies and practices regarding your information and how we treat it. If you do not agree with our policies and practices, your choice is not to use our bot. By accessing or using this bot, you agree to this privacy policy. This policy may change from time to time (see Changes to Our Privacy Policy). Your continued use of this bot after we make changes is deemed to be acceptance of those changes, so please check the policy periodically for updates.

THE INFORMATION WE COLLECT AND HOW WE COLLECT IT
When you use the bot and save settings, we collect and store your discord user id, as well as the preferences you specify.

THIRD-PARTY WEBSITES
Messages distributed by our bot may contain links to third-party websites. These linked websites are not under our control, and we are not responsible for the privacy practices or the contents of any such linked website or any link contained in any linked website. We provide such links only as a convenience, and the inclusion of a link on the website does not imply endorsement of the linked website by Simple Tarot Bot. If you provide any personal data through any such third-party website, your transaction will occur on the third party’s website (not this website) and the personal data you provide will be collected by and controlled by the privacy policy of that third party. We recommend that you familiarize yourself with the privacy policies and practices of any third parties. PLEASE NOTE THAT THIS PRIVACY POLICY DOES NOT ADDRESS THE PRIVACY OR INFORMATION PRACTICES OF ANY THIRD PARTIES.

THE WAY WE USE INFORMATION
This Privacy Statement governs use of the information that you provide to us through the bot. It does not govern the manner in which we may use information obtained from other sources (such as public records) or from you by means other than this bot. We and other entities that we are involved in, or provide support for, the operation of this bot or other purposes use information that we collect about you or that you provide to us, including any personal information:

To provide you with the services of the bot using your specified preferences.
In any other way we may describe when you provide the information.
For any other purpose with your consent.
We may also use your information if provided to us to contact you about our own and third-party services and products that may be of interest to you. If you do not want us to use your information in this way, you can opt out of receiving this information by so indicating in your registration/preferences file or by notifying us.

CHANGES TO OUR PRIVACY POLICY
It is our policy to post any changes we make to our privacy policy on this page. If we make material changes to how we treat our users’ personal information, we will notify you by e-mail to the primary e-mail address specified in your registration information if any has been established and/or through a notice on the website home page. The date the privacy policy was last revised is identified at the top of the page. If information has been collected, you are responsible for ensuring we have an up-to- date active and deliverable e-mail address for you, and for periodically visiting our website and this privacy policy to check for any changes.


CONTACT INFORMATION
To ask questions or comment about this Privacy Policy and our privacy practices, please contact us via Discord.
Empty file added common/__init__.py
Empty file.
File renamed without changes.
3 changes: 2 additions & 1 deletion tarot.py → common/tarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __new__(cls, shortname, label, longname, global_d = True):

DEFAULT = ("default", "Default", "Default cards")
SWISS = ("swiss", "Swiss", "IJJ Swiss cards")
PLANET_SCUM = ("planetscum", "Planet Scum", "Planet Scum Custom Cards", False)

@unique
class MajorMinor(Enum):
Expand Down Expand Up @@ -358,7 +359,7 @@ def makeImgList (cards: List[Card], deck: Decks):
"""Returns a list of Images corresponding to cards."""
imgarray = []
for c in cards:
newcard = Image.open(path.join("decks",deck.shortname,c.code + ".jpg")).convert("RGBA")
newcard = Image.open(path.join("..","decks",deck.shortname,c.code + ".jpg")).convert("RGBA")
if not c.up:
newcardrev = newcard.rotate(180, expand = 1)
imgarray.append(newcardrev)
Expand Down
Binary file added decks/planetscum/0M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/10C.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/10M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/10P.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/10S.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/10W.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/11M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/12M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/13M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/14M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/15M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/16M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/17M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/18M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/19M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/1M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/20M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/21M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/2C.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/2M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/2P.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/2S.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/2W.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/3C.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/3M.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added decks/planetscum/3P.jpg
Binary file added decks/planetscum/3S.jpg
Binary file added decks/planetscum/3W.jpg
Binary file added decks/planetscum/4C.jpg
Binary file added decks/planetscum/4M.jpg
Binary file added decks/planetscum/4P.jpg
Binary file added decks/planetscum/4S.jpg
Binary file added decks/planetscum/4W.jpg
Binary file added decks/planetscum/5C.jpg
Binary file added decks/planetscum/5M.jpg
Binary file added decks/planetscum/5P.jpg
Binary file added decks/planetscum/5S.jpg
Binary file added decks/planetscum/5W.jpg
Binary file added decks/planetscum/6C.jpg
Binary file added decks/planetscum/6M.jpg
Binary file added decks/planetscum/6P.jpg
Binary file added decks/planetscum/6S.jpg
Binary file added decks/planetscum/6W.jpg
Binary file added decks/planetscum/7C.jpg
Binary file added decks/planetscum/7M.jpg
Binary file added decks/planetscum/7P.jpg
Binary file added decks/planetscum/7S.jpg
Binary file added decks/planetscum/7W.jpg
Binary file added decks/planetscum/8C.jpg
Binary file added decks/planetscum/8M.jpg
Binary file added decks/planetscum/8P.jpg
Binary file added decks/planetscum/8S.jpg
Binary file added decks/planetscum/8W.jpg
Binary file added decks/planetscum/9C.jpg
Binary file added decks/planetscum/9M.jpg
Binary file added decks/planetscum/9P.jpg
Binary file added decks/planetscum/9S.jpg
Binary file added decks/planetscum/9W.jpg
Binary file added decks/planetscum/AC.jpg
Binary file added decks/planetscum/AP.jpg
Binary file added decks/planetscum/AS.jpg
Binary file added decks/planetscum/AW.jpg
Binary file added decks/planetscum/KC.jpg
Binary file added decks/planetscum/KNC.jpg
Binary file added decks/planetscum/KNP.jpg
Binary file added decks/planetscum/KNS.jpg
Binary file added decks/planetscum/KNW.jpg
Binary file added decks/planetscum/KP.jpg
Binary file added decks/planetscum/KS.jpg
Binary file added decks/planetscum/KW.jpg
Binary file added decks/planetscum/PC.jpg
Binary file added decks/planetscum/PP.jpg
Binary file added decks/planetscum/PS.jpg
Binary file added decks/planetscum/PW.jpg
Binary file added decks/planetscum/QC.jpg
Binary file added decks/planetscum/QP.jpg
Binary file added decks/planetscum/QS.jpg
Binary file added decks/planetscum/QW.jpg
Empty file added discordbot/__init__.py
Empty file.
7 changes: 5 additions & 2 deletions changeGuildSettings.py → discordbot/changeGuildSettings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import shelve
from tarot import Decks
from ..common.tarot import Decks

# add non-standard deck to the guilds
def addCustomDeck(guildid, deck):
Expand All @@ -11,4 +11,7 @@ def addCustomDeck(guildid, deck):

#put custom deck into 605900319922061342
if __name__ == "__main__":
# addCustomDeck(605900319922061342, )
addCustomDeck("605900319922061342", Decks.PLANET_SCUM)
# test servers. remove these later
addCustomDeck("357633267861553162", Decks.PLANET_SCUM)
addCustomDeck("410850945229127692", Decks.PLANET_SCUM)
2 changes: 1 addition & 1 deletion components.py → discordbot/components.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import discord
from tarot import ReadingType, Decks, MajorMinor
from ..common.tarot import ReadingType, Decks, MajorMinor
from handler import handle, READING_DEFAULTS
import shelve
from itertools import chain
Expand Down
4 changes: 2 additions & 2 deletions discordslash.py → discordbot/discordslash.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import tarot
from tarot import ReadingType, Decks
from ..common import tarot
from ..common.tarot import ReadingType, Decks
import discord
from dotenv import load_dotenv
from io import BytesIO
Expand Down
4 changes: 2 additions & 2 deletions handler.py → discordbot/handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import discord
from io import BytesIO
import tarot
from tarot import ReadingType, Decks, MajorMinor
from ..common import tarot
from ..common.tarot import ReadingType, Decks, MajorMinor
import shelve

color = discord.Colour(0x6b1bf8)
Expand Down
8 changes: 6 additions & 2 deletions main.py → discordbot/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# attempting to switch to pycord because interactions has annoyed me
import os
from tarot import ReadingType
from ..common.tarot import ReadingType
from dotenv import load_dotenv
import discord
from components import ReadingSelectorView, AboutView, SettingsView
Expand Down Expand Up @@ -60,4 +60,8 @@ async def _do_reading(ctx):
addCommand(t)
help_message += "/{}: {}\n".format(t.id, t.description)

bot.run(token)
def main():
bot.run(token)

if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions main_interactions.py → discordbot/main_interactions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import interactions
from interactions import Embed, EmbedField, EmbedImageStruct, Attachment
import os
import tarot
from tarot import ReadingType, Decks
from ..common import tarot
from ..common.tarot import ReadingType, Decks
from dotenv import load_dotenv
from io import BytesIO
from components import createComponents, default_components, about_components, settings_components, start_reading_components
Expand Down
13 changes: 13 additions & 0 deletions discordbot/numServers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from dotenv import load_dotenv
import discord
import os

load_dotenv()
bot = discord.Bot()

@bot.event
async def on_ready():
print("bot is running")
print(len(bot.guilds))

bot.run(os.getenv('DISCORD_TOKEN'))
16 changes: 16 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
aiodns==3.0.0
aiohttp==3.8.1
aiosignal==1.2.0
anyio==3.6.1
APScheduler==3.9.1
async-timeout==4.0.2
attrs==21.4.0
brotlipy==0.7.0
cachetools==5.2.0
cchardet==2.1.7
certifi==2022.6.15
cffi==1.15.0
chardet==4.0.0
charset-normalizer==2.0.12
colorama==0.4.4
frozenlist==1.3.0
h11==0.12.0
httpcore==0.15.0
httpx==0.23.0
idna==3.3
multidict==6.0.2
orjson==3.6.8
Expand All @@ -18,5 +25,14 @@ py-cord==2.0.0b7
pycares==4.1.2
pycparser==2.21
python-dotenv==0.20.0
python-telegram-bot==20.0a1
pytz==2022.1
pytz-deprecation-shim==0.1.0.post0
rfc3986==1.5.0
six==1.16.0
sniffio==1.2.0
tornado==6.1
typing_extensions==4.2.0
tzdata==2022.1
tzlocal==4.2
yarl==1.7.2
4 changes: 4 additions & 0 deletions runDiscord.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from discordbot import main

if __name__ == '__main__':
main.main()
4 changes: 4 additions & 0 deletions runTelegram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from telegrambot import main

if __name__ == '__main__':
main.main()
Empty file added telegrambot/__init__.py
Empty file.
74 changes: 74 additions & 0 deletions telegrambot/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import os
from uuid import uuid4
from telegram import Update, InlineQueryResultArticle, InlineQueryResultPhoto, InputTextMessageContent
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, filters, MessageHandler, InlineQueryHandler
from dotenv import load_dotenv

load_dotenv()

startText = "I'm TarotBot! You can get a tarot reading with /tarot, or update your settings with /settings. Get help with /help"

# When a user starts interaction with a bot
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=startText
)

# For when an unknown command is sent
async def unknown(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(chat_id=update.effective_chat.id, text="Sorry, I didn't understand that command.")

# Help command
async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=startText
)

# TODO: edit settings
async def change_settings(update: Update, context: ContextTypes.DEFAULT_TYPE):
pass


# TODO: conduct a reading
# TODO: inline query
async def inline_query(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Handle the inline query. This is run when you type: @botusername <query>"""
# query = update.inline_query.query

# if query == "":
# return

results = [
InlineQueryResultPhoto(
id=str(uuid4()),
photo_url=???,
title=???
description=???,
caption=???
)
]

await update.inline_query.answer(
results,
switch_pm_text="Change Tarot Settings"
)


def main():
application = ApplicationBuilder().token(os.getenv('TELEGRAM_API_TOKEN')).build()

application.add_handler(CommandHandler('start', start))
application.add_handler(CommandHandler('settings', change_settings))
application.add_handler(CommandHandler('help', help_command))
application.add_handler(InlineQueryHandler(inline_query))

# Should be the last handler
application.add_handler(MessageHandler(filters.COMMAND, unknown))


application.run_polling()

if __name__ == '__main__':
main()

0 comments on commit 553402b

Please sign in to comment.