Compare commits

..

No commits in common. "main" and "shittification" have entirely different histories.

7 changed files with 48 additions and 141 deletions

1
.envrc
View File

@ -1 +0,0 @@
use flake .

12
Pipfile Normal file
View File

@ -0,0 +1,12 @@
[[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
View File

@ -1,61 +0,0 @@
{
"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
}

View File

@ -1,27 +0,0 @@
{
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
View File

@ -1,31 +1 @@
#!/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"
docker buildx build --platform linux/arm64 -t yen3k/sesh-secretary:1.0 --push --file Dockerfile .

View File

@ -1 +1,16 @@
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'

View File

@ -1,7 +1,6 @@
#!/usr/bin/python
from telegram import Update
from telegram.ext import Application, CommandHandler, filters
from telegram.ext import Updater, CommandHandler, Filters
import os
from random import randrange
import sys
@ -9,8 +8,7 @@ import sys
SAVED_PATH = '/var/lib/seshsecretary/saved.txt'
CHATIDS_PATH = '/var/lib/seshsecretary/chatids.txt'
async def _list(update, context):
def _list(update, context):
chat_id = update.effective_chat.id
if not check_chat_id(chat_id):
@ -21,11 +19,11 @@ async def _list(update, context):
for line in f:
response += line.split()[0] + "\n"
if response == "":
await context.bot.send_message(chat_id, "Ingen gemte beskeder :(", 'MARKDOWN')
context.bot.send_message(chat_id, "Ingen gemte beskeder :(", 'MARKDOWN')
else:
await context.bot.send_message(chat_id, response, 'MARKDOWN')
context.bot.send_message(chat_id, response, 'MARKDOWN')
async def random(update, context):
def random(update, context):
chat_id = update.effective_chat.id
if not check_chat_id(chat_id):
@ -36,9 +34,9 @@ async def random(update, context):
message = lines[randrange(len(lines))]
message_id = message.split()[1]
from_chat_id = message.split()[2]
await context.bot.forward_message(chat_id, from_chat_id, message_id)
context.bot.forward_message(chat_id, from_chat_id, message_id)
async def get(update, context):
def get(update, context):
chat_id = update.effective_chat.id
if not check_chat_id(chat_id):
@ -54,12 +52,12 @@ async def get(update, context):
break
if message_id == "":
await update.message.reply_text(
update.message.reply_text(
"{} findes ik!".format(name))
else:
await context.bot.forward_message(chat_id, from_chat_id, message_id)
context.bot.forward_message(chat_id, from_chat_id, message_id)
async def save(update, context):
def save(update, context):
chat_id = update.effective_chat.id
if not check_chat_id(chat_id):
@ -76,9 +74,9 @@ async def save(update, context):
if cont:
with open(SAVED_PATH, "a") as f:
f.write(name + " " + str(message_id) + " " + str(chat_id) + "\n")
await update.message.reply_text(name + " er gemt!")
update.message.reply_text(name + " er gemt!")
else:
await update.message.reply_text(name + " findes allerede :(")
update.message.reply_text(name + " findes allerede :(")
def main():
if not os.path.isfile(SAVED_PATH):
@ -90,14 +88,15 @@ def main():
if token is None:
sys.exit("Missing environment variable: SESHSECRETARY_TOKEN")
application = Application.builder().token(token).build()
updater = Updater(token, use_context=True)
application.add_handler(CommandHandler("list", _list))
application.add_handler(CommandHandler("get", get))
application.add_handler(CommandHandler("random", random))
application.add_handler(CommandHandler("save", save, filters.REPLY))
updater.dispatcher.add_handler(CommandHandler("list", _list))
updater.dispatcher.add_handler(CommandHandler("get", get))
updater.dispatcher.add_handler(CommandHandler("random", random))
updater.dispatcher.add_handler(CommandHandler("save", save, Filters.reply))
application.run_polling(allowed_updates=Update.ALL_TYPES)
updater.start_polling()
updater.idle()
def check_chat_id(chatid):
with open(CHATIDS_PATH) as f: