Compare commits
4 Commits
shittifica
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b626b45ed | |||
| 865b642ac9 | |||
| 5147a56672 | |||
| 22d91491dc |
12
Pipfile
12
Pipfile
@ -1,12 +0,0 @@
|
|||||||
[[source]]
|
|
||||||
name = "pypi"
|
|
||||||
url = "https://pypi.org/simple"
|
|
||||||
verify_ssl = true
|
|
||||||
|
|
||||||
[dev-packages]
|
|
||||||
|
|
||||||
[packages]
|
|
||||||
python-telegram-bot = "*"
|
|
||||||
|
|
||||||
[requires]
|
|
||||||
python_version = "3.8"
|
|
||||||
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1709126324,
|
||||||
|
"narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "d465f4819400de7c8d874d50b982301f28a84605",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1709101946,
|
||||||
|
"narHash": "sha256-TsySgcWm/GlbYdL3AEva49ceeI2BdPQ7muwfYNr1fwo=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "d53c2037394da6fe98decca417fc8fda64bf2443",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
27
flake.nix
Normal file
27
flake.nix
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
description = "Python3 telegram bot environment";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, flake-utils, ... }:
|
||||||
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
};
|
||||||
|
pythonEnv = pkgs.python3.withPackages (ps: with ps; [
|
||||||
|
python-telegram-bot
|
||||||
|
]);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
pythonEnv
|
||||||
|
];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
32
push.sh
32
push.sh
@ -1 +1,31 @@
|
|||||||
docker buildx build --platform linux/arm64 -t yen3k/sesh-secretary:1.0 --push --file Dockerfile .
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
DATE=$(date +%Y-%m-%d)
|
||||||
|
|
||||||
|
LOCAL_IMAGE="sesh-secretary"
|
||||||
|
PRIVATE_IMAGE="yenhub.yenting.dk/${LOCAL_IMAGE}"
|
||||||
|
DOCKERHUB_IMAGE="docker.io/yen3k/${LOCAL_IMAGE}"
|
||||||
|
|
||||||
|
# Build once (arm64)
|
||||||
|
podman buildx build \
|
||||||
|
--arch arm64 \
|
||||||
|
-t "${LOCAL_IMAGE}:${DATE}" \
|
||||||
|
-t "${LOCAL_IMAGE}:latest" \
|
||||||
|
-f Dockerfile .
|
||||||
|
|
||||||
|
# Tag for private registry
|
||||||
|
podman tag "${LOCAL_IMAGE}:${DATE}" "${PRIVATE_IMAGE}:${DATE}"
|
||||||
|
podman tag "${LOCAL_IMAGE}:latest" "${PRIVATE_IMAGE}:latest"
|
||||||
|
|
||||||
|
# Tag for Docker Hub
|
||||||
|
podman tag "${LOCAL_IMAGE}:${DATE}" "${DOCKERHUB_IMAGE}:${DATE}"
|
||||||
|
podman tag "${LOCAL_IMAGE}:latest" "${DOCKERHUB_IMAGE}:latest"
|
||||||
|
|
||||||
|
# Push to private registry
|
||||||
|
podman push "${PRIVATE_IMAGE}:${DATE}"
|
||||||
|
podman push "${PRIVATE_IMAGE}:latest"
|
||||||
|
|
||||||
|
# Push to Docker Hub
|
||||||
|
podman push "${DOCKERHUB_IMAGE}:${DATE}"
|
||||||
|
podman push "${DOCKERHUB_IMAGE}:latest"
|
||||||
|
|||||||
@ -1,16 +1 @@
|
|||||||
#
|
python-telegram-bot==22.0
|
||||||
# These requirements were autogenerated by pipenv
|
|
||||||
# To regenerate from the project's Pipfile, run:
|
|
||||||
#
|
|
||||||
# pipenv lock --requirements
|
|
||||||
#
|
|
||||||
|
|
||||||
-i https://pypi.org/simple
|
|
||||||
certifi==2020.6.20
|
|
||||||
cffi==1.14.2
|
|
||||||
cryptography==3.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
|
|
||||||
decorator==4.4.2
|
|
||||||
pycparser==2.20; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
|
||||||
python-telegram-bot==12.8
|
|
||||||
six==1.15.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
|
||||||
tornado==6.0.4; python_version >= '3.5'
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
from telegram.ext import Updater, CommandHandler, Filters
|
from telegram import Update
|
||||||
|
from telegram.ext import Application, CommandHandler, filters
|
||||||
import os
|
import os
|
||||||
from random import randrange
|
from random import randrange
|
||||||
import sys
|
import sys
|
||||||
@ -8,7 +9,8 @@ import sys
|
|||||||
SAVED_PATH = '/var/lib/seshsecretary/saved.txt'
|
SAVED_PATH = '/var/lib/seshsecretary/saved.txt'
|
||||||
CHATIDS_PATH = '/var/lib/seshsecretary/chatids.txt'
|
CHATIDS_PATH = '/var/lib/seshsecretary/chatids.txt'
|
||||||
|
|
||||||
def _list(update, context):
|
|
||||||
|
async def _list(update, context):
|
||||||
chat_id = update.effective_chat.id
|
chat_id = update.effective_chat.id
|
||||||
|
|
||||||
if not check_chat_id(chat_id):
|
if not check_chat_id(chat_id):
|
||||||
@ -19,11 +21,11 @@ def _list(update, context):
|
|||||||
for line in f:
|
for line in f:
|
||||||
response += line.split()[0] + "\n"
|
response += line.split()[0] + "\n"
|
||||||
if response == "":
|
if response == "":
|
||||||
context.bot.send_message(chat_id, "Ingen gemte beskeder :(", 'MARKDOWN')
|
await context.bot.send_message(chat_id, "Ingen gemte beskeder :(", 'MARKDOWN')
|
||||||
else:
|
else:
|
||||||
context.bot.send_message(chat_id, response, 'MARKDOWN')
|
await context.bot.send_message(chat_id, response, 'MARKDOWN')
|
||||||
|
|
||||||
def random(update, context):
|
async def random(update, context):
|
||||||
chat_id = update.effective_chat.id
|
chat_id = update.effective_chat.id
|
||||||
|
|
||||||
if not check_chat_id(chat_id):
|
if not check_chat_id(chat_id):
|
||||||
@ -34,9 +36,9 @@ def random(update, context):
|
|||||||
message = lines[randrange(len(lines))]
|
message = lines[randrange(len(lines))]
|
||||||
message_id = message.split()[1]
|
message_id = message.split()[1]
|
||||||
from_chat_id = message.split()[2]
|
from_chat_id = message.split()[2]
|
||||||
context.bot.forward_message(chat_id, from_chat_id, message_id)
|
await context.bot.forward_message(chat_id, from_chat_id, message_id)
|
||||||
|
|
||||||
def get(update, context):
|
async def get(update, context):
|
||||||
chat_id = update.effective_chat.id
|
chat_id = update.effective_chat.id
|
||||||
|
|
||||||
if not check_chat_id(chat_id):
|
if not check_chat_id(chat_id):
|
||||||
@ -52,12 +54,12 @@ def get(update, context):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if message_id == "":
|
if message_id == "":
|
||||||
update.message.reply_text(
|
await update.message.reply_text(
|
||||||
"{} findes ik!".format(name))
|
"{} findes ik!".format(name))
|
||||||
else:
|
else:
|
||||||
context.bot.forward_message(chat_id, from_chat_id, message_id)
|
await context.bot.forward_message(chat_id, from_chat_id, message_id)
|
||||||
|
|
||||||
def save(update, context):
|
async def save(update, context):
|
||||||
chat_id = update.effective_chat.id
|
chat_id = update.effective_chat.id
|
||||||
|
|
||||||
if not check_chat_id(chat_id):
|
if not check_chat_id(chat_id):
|
||||||
@ -74,9 +76,9 @@ def save(update, context):
|
|||||||
if cont:
|
if cont:
|
||||||
with open(SAVED_PATH, "a") as f:
|
with open(SAVED_PATH, "a") as f:
|
||||||
f.write(name + " " + str(message_id) + " " + str(chat_id) + "\n")
|
f.write(name + " " + str(message_id) + " " + str(chat_id) + "\n")
|
||||||
update.message.reply_text(name + " er gemt!")
|
await update.message.reply_text(name + " er gemt!")
|
||||||
else:
|
else:
|
||||||
update.message.reply_text(name + " findes allerede :(")
|
await update.message.reply_text(name + " findes allerede :(")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if not os.path.isfile(SAVED_PATH):
|
if not os.path.isfile(SAVED_PATH):
|
||||||
@ -88,15 +90,14 @@ def main():
|
|||||||
if token is None:
|
if token is None:
|
||||||
sys.exit("Missing environment variable: SESHSECRETARY_TOKEN")
|
sys.exit("Missing environment variable: SESHSECRETARY_TOKEN")
|
||||||
|
|
||||||
updater = Updater(token, use_context=True)
|
application = Application.builder().token(token).build()
|
||||||
|
|
||||||
updater.dispatcher.add_handler(CommandHandler("list", _list))
|
application.add_handler(CommandHandler("list", _list))
|
||||||
updater.dispatcher.add_handler(CommandHandler("get", get))
|
application.add_handler(CommandHandler("get", get))
|
||||||
updater.dispatcher.add_handler(CommandHandler("random", random))
|
application.add_handler(CommandHandler("random", random))
|
||||||
updater.dispatcher.add_handler(CommandHandler("save", save, Filters.reply))
|
application.add_handler(CommandHandler("save", save, filters.REPLY))
|
||||||
|
|
||||||
updater.start_polling()
|
application.run_polling(allowed_updates=Update.ALL_TYPES)
|
||||||
updater.idle()
|
|
||||||
|
|
||||||
def check_chat_id(chatid):
|
def check_chat_id(chatid):
|
||||||
with open(CHATIDS_PATH) as f:
|
with open(CHATIDS_PATH) as f:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user