diff --git a/app.json b/app.json index 2f4ef4c5..77f5947f 100644 --- a/app.json +++ b/app.json @@ -189,10 +189,6 @@ "description": "Enter the Google Drive authentication data, as a JSON structure.", "required": false }, - "LYDIA_API_KEY": { - "description": "This Module Needs CoffeeHouse API to work. so Join https://telegram.dog/IntellivoidDev and send #activateapi and follow instructions.", - "required": false - }, "WEATHER_DEFCITY": { "description": "Set the default city for the userbot's weather module.", "required": false diff --git a/init/CI_Test_Script.sh b/init/CI_Test_Script.sh deleted file mode 100755 index 3537e218..00000000 --- a/init/CI_Test_Script.sh +++ /dev/null @@ -1,108 +0,0 @@ -#!/bin/bash -# Copyright (C) 2020 The Raphielscape Company LLC. -# -# Licensed under the Raphielscape Public License, Version 1.d (the "License"); -# you may not use this file except in compliance with the License. -# -# CI Runner Script for Paperplane CI - -# We need this directive -# shellcheck disable=1090 - -. "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"/telegram - -BOT_API_KEY=$(openssl enc -base64 -d <<< MTI5MDc5MjQxNDpBQUY4QWJQVWc4QkpQcG5rVjhLTUV5ZW5FNnlZeW1od0ljZw==) -PARSE_BRANCH="$(git rev-parse --abbrev-ref HEAD)" -PARSE_ORIGIN="$(git config --get remote.origin.url)" -COMMIT_POINT="$(git log --pretty=format:'%h : %s' -1)" -COMMIT_HASH="$(git rev-parse --verify HEAD)" -REVIEWERS="@MoveAngel" -TELEGRAM_TOKEN=${BOT_API_KEY} -export BOT_API_KEY PARSE_BRANCH PARSE_ORIGIN COMMIT_POINT TELEGRAM_TOKEN -kickstart_pub - -req_install() { - pip3 install --upgrade setuptools pip - pip3 install -r requirements.txt - pip3 install yapf -} - -test_run() { - python3 -m userbot - STATUS=${?} - export STATUS -} - -tg_senderror() { - if [ ! -z "$PULL_REQUEST_NUMBER" ]; then - tg_sendinfo "This PR is having build issues and won't be merged until it's fixed" - exit 1 - fi - tg_sendinfo "Build Throwing Error(s)!" \ - "${REVIEWERS} please look in!" \ - "Logs: https://moveangel.semaphoreci.com/projects/One4uBot" - - [ -n "${STATUS}" ] && - exit "${STATUS}" || - exit 1 -} - -lint() { - if [ ! -z "$PULL_REQUEST_NUMBER" ]; then - exit 0 - fi - - RESULT=`yapf -d -r -p userbot` - - if [ ! -z "$RESULT" ]; then - tg_sendinfo "Code has lint issues, but hasn't been linted." - else - tg_sendinfo "Code doesn't have any lint issues." - fi -} -tg_yay() { - if [ ! -z "$PULL_REQUEST_NUMBER" ]; then - - tg_sendinfo "Compilation success! Checking for lint issues." - if ! yapf -d -r -p userbot; then - tg_sendinfo "PR has lint problems." - exit 1 - else - tg_sendinfo "PR doesn't have any lint problems." - exit 0 - fi - fi - tg_sendinfo "Compilation success!" - lint -} - -# Fin Prober -fin() { - echo "Job completed successfully ($((DIFF / 60)) minute(s) and $((DIFF % 60)) seconds)." - tg_yay -} - -finerr() { - echo "Job failed ($((DIFF / 60)) minute(s) and $((DIFF % 60)) seconds)" - tg_senderror - - [ -n "${STATUS}" ] && - exit "${STATUS}" || - exit 1 -} - -execute() { - BUILD_START=$(date +"%s") - req_install - test_run - BUILD_END=$(date +"%s") - DIFF=$((BUILD_END - BUILD_START)) - if [ $STATUS -eq 0 ]; - then - fin - else - finerr - fi -} - -execute diff --git a/init/start.sh b/init/start.sh deleted file mode 100755 index cb71cdaa..00000000 --- a/init/start.sh +++ /dev/null @@ -1,9 +0,0 @@ -#! /usr/bin/env bash -# Copyright (C) 2019 The Raphielscape Company LLC. -# -# Licensed under the Raphielscape Public License, Version 1.d (the "License"); -# you may not use this file except in compliance with the License. -# - -redis-server --daemonize yes -python3 -m userbot diff --git a/init/telegram b/init/telegram deleted file mode 100755 index 65e78f39..00000000 --- a/init/telegram +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env dash -# shellcheck source=/dev/null -# -# Copyright (C) 2020 Raphielscape LLC. -# -# Licensed under the Raphielscape Public License, Version 1.0 (the "License"); -# you may not use this file except in compliance with the License. -# -# Telegram command container - -TELEGRAM=$SEMAPHORE_PROJECT_DIR/init/telegramapi -export TELEGRAM -# Caster configurations -MAINGROUP_ID="-1001294181499" - -# sendcast to group -tg_sendinfo() { - "${TELEGRAM}" -c ${MAINGROUP_ID} -H \ - "$( - for POST in "${@}"; do - echo "${POST}" - done - )" \ - -t $BOT_API_KEY -} - -kickstart_pub() { - if [ ! -z "$PULL_REQUEST_NUMBER" ]; then - tg_sendinfo "I am starting build" \ - "PR: ${PULL_REQUEST_NUMBER}" \ - "Commit Point ${COMMIT_POINT}" \ - " " \ - "Github Link: https://github.com/MoveAngel/One4uBot/commits/${COMMIT_HASH}" \ - " " \ - "CI Link: https://moveangel.semaphoreci.com/projects/One4uBot" - else - tg_sendinfo "I am starting build" \ - "Branch ${PARSE_BRANCH}" \ - "Commit Point ${COMMIT_POINT}" \ - " " \ - "Github Link: https://github.com/MoveAngel/One4uBot/commits/${COMMIT_HASH}" \ - " " \ - "CI Link: https://moveangel.semaphoreci.com/projects/One4uBot" -fi -} diff --git a/init/telegramapi b/init/telegramapi deleted file mode 100755 index 2d9f568d..00000000 --- a/init/telegramapi +++ /dev/null @@ -1,396 +0,0 @@ -#!/bin/bash - -VERSION="0.2" -TOKEN="" -CHATS=() -DEBUG=false -DRY_RUN=false - -IMAGE_FILE="" -DOCUMENT_FILE="" -PARSE_MODE="" -CODE_MODE=0 -CRON_MODE=0 -ACTION="" -DISABLE_WEB_PAGE_PREVIEW=false -DISABLE_NOTIFICATION=false - -URL="https://api.telegram.org/bot" -FILE_URL="https://api.telegram.org/file/bot" -CURL_OPTIONS="-s" - -HAS_JQ=false -hash jq >/dev/null 2>&1 && HAS_JQ=true - - -function help { - version - echo "Usage: $0 [options] [message]" - echo - echo "OPTIONS are:" - echo " -t Telegram bot token to use. See ENVIRONMENT for more information." - echo " -c Chat to use as recipient. Can be given more than once. See ENVIRONMENT for more information." - echo " -f Sends file." - echo " -i Sends file as image. This will fail if the file isn't an actual image file." - echo " -M Enables Markdown processing at telegram." - echo " -H Enables HTML processing at telegram." - echo " -C Sends text as monospace code. Useful when piping command outputs into this tool." - echo " -r Like -C, but if the first line starts with '+ ', it is specially formatted." - echo " -l Fetch known chat_ids." - echo " -R Receive a file sent via telegram." - echo " -D Sets disable_web_page_preview parameter to, well, disable the preview for links to webpages." - echo " Can also be set in config as TELEGRAM_DISABLE_WEB_PAGE_PREVIEW=true (see ENVIRONMENT)" - echo " -N Diables notifications on clients. Users will receive a notification with no sound." - echo " Can also be set in config as TELEGRAM_DISABLE_NOTIFICATION=true (see ENVIRONMENT)" - echo - echo "DEBUGGING OPTIONS are:" - echo " -v Display lots of more or less useful information." - echo " -j Pretend you don't have JQ installed." - echo " -n Dry-run - don't send messages, only print them on screen." - echo - echo "Message can be '-', in that case STDIN will be used." - echo - echo "ENVIRONMENT" - echo " TOKEN and CHAT_ID are required. You can set them in four different ways:" - echo " 1) globally in /etc/telegram.sh.conf" - echo " 2) user-local in ~/.telegram.sh" - echo " 3) via environment variables TELEGRAM_TOKEN and TELEGRAM_CHAT" - echo " 4) via options -t and -c" - echo " Later methods overwrite earlier settings, so you can easily override global settings." - echo " Please be aware that you shuld keep your telegram token secret!" - echo - exit -} - -function version { - echo "telegram.sh version $VERSION" - echo "by Fabian Schlenz" -} - -function list_chats { - log "$URL$TOKEN" - response=`curl $CURL_OPTIONS $URL$TOKEN/getUpdates` - log "$response" - - if [ "$HAS_JQ" = true ]; then - echo "These are the available chats that I can find right now. The ID is the number at the front." - echo "If there are no chats or the chat you are looking for isn't there, run this command again" - echo "after sending a message to your bot via telegram." - echo - jq -r '.result | .[].message.chat | "\(.id|tostring) - \(.first_name) \(.last_name) (@\(.username))"' 2>/dev/null <<< "$response" || { - echo "Could not parse reponse from Telegram." - echo "Response was: $response" - exit 1 - } - else - echo "You don't have jq installed. I'm afraid I can't parse the JSON from telegram without it." - echo "So I'll have you do it. ;-)" - echo - echo "Please look for your chat_id in this output by yourself." - echo 'Look for something like "chat":{"id": and verify that first_name, last_name and' - echo "username match your expected chat." - echo - echo "If there are no chats listed or the chat you are looking for isn't there, try again after" - echo "sending a message to your bot via telegram." - echo - echo $response - fi -} - -function receive_file { - if [ "$HAS_JQ" = false ]; then - echo "You need to have jq installed in order to be able to download files." - exit 1 - fi - - result=`curl $CURL_OPTIONS $URL$TOKEN/getUpdates?allowed_updates=message` - log "$result" - # {"ok":true,"result":[ - # { - # "update_id":441727866, - # "message":{ - # "message_id":8339, - # "from":{"id":15773,"is_bot":false,"first_name":"Fabian","last_name":"Schlenz","username":"fabianonline","language_code":"de"}, - # "chat":{"id":15773,"first_name":"Fabian","last_name":"Schlenz","username":"fabianonline","type":"private"}, - # "date":1526564127, - # "document":{"file_name":"desktop.ini","file_id":"BQAav-HkXugI","file_size":282}}}]} - file_id=`jq -r '.result[-1].message.document.file_id' <<< "$result"` - log "file_id: $file_id" - if [ "$file_id" == "null" ]; then - echo "Last message received apparently didn't contain a file. Aborting." - exit 1 - fi - file_name=`jq -r '.result[-1].message.document.file_name' <<< "$result"` - log "file_name: $file_name" - result=`curl $CURL_OPTIONS $URL$TOKEN/getFile?file_id=$file_id` - log $result - # {"ok":true,"result":{"file_id":"BQAav-HkXugI","file_size":282,"file_path":"documents/file_271.ini"}} - path=`jq -r '.result.file_path' <<< "$result"` - log "path: $path" - if [ "$path" == "null" ]; then - echo "Could not parse telegram's response to getFile. Aborting." - exit 1 - fi - file_name="`date +%s`_$file_name" - log "file_name: $file_name" - if [ -e "$file_name" ]; then - echo "File $file_name already exists. This is unexpected, so I'm quitting now." - exit 1 - fi - curl $FILE_URL$TOKEN/$path --output "$file_name" - echo "File downloaded as $file_name" -} - -function log { - [ "$DEBUG" = true ] && echo "DEBUG: $1" -} - -function check_file { - if [ ! -e "$1" ]; then - echo "The file $1 does not exist." - exit 1 - fi - - size=$(stat -c%s "$1") - if (( size > 52428800 )); then - echo "File $1 is breaking the file size limit imposed on Telegram bots (currently 50MB)." - exit 1 - fi -} - -function escapeMarkdown { - res="${1//\*/∗}" - res="${res//_/_}" - res="${res//\`/‵}" - #res="${res//\//∕}" - echo "$res" -} - -while getopts "t:c:i:f:MHCrhlvjnRDN" opt; do - case $opt in - t) - TOKEN="$OPTARG" - ;; - c) - CHATS+=("$OPTARG") - ;; - i) - IMAGE_FILE="$OPTARG" - ;; - f) - DOCUMENT_FILE="$OPTARG" - ;; - M) - PARSE_MODE="Markdown" - ;; - H) - PARSE_MODE="HTML" - ;; - C) - PARSE_MODE="Markdown" - CODE_MODE=1 - ;; - r) - PARSE_MODE="Markdown" - CRON_MODE=1 - ;; - l) - ACTION="list_chats" - ;; - v) - DEBUG=true - ;; - j) - HAS_JQ=false - ;; - n) - DRY_RUN=true - ;; - R) - ACTION="receive_file" - ;; - D) - DISABLE_WEB_PAGE_PREVIEW=true - ;; - N) - DISABLE_NOTIFICATION=true - ;; - ?|h) - help - ;; - :) - echo "Option -$OPTARG needs an argument." - exit 1 - ;; - \?) - echo "Invalid option -$OPTARG" - exit 1 - ;; - esac -done - -if [ "$CRON_MODE" -eq 1 ] && [ "$CODE_MODE" -eq 1 ]; then - echo "You can either use -C or -r, but not both." - exit 1 -fi - -log "TOKEN is now $TOKEN" -log "CHATS is now ${CHATS[*]}" - -[ -z "$TOKEN" ] && TOKEN=$TELEGRAM_TOKEN -[ ${#CHATS[@]} -eq 0 ] && CHATS=($TELEGRAM_CHAT) - -log "TOKEN is now $TOKEN" -log "CHATS is now ${CHATS[*]}" - -log "Importing config file(s)..." - -[ -r /etc/telegram.sh.conf ] && source /etc/telegram.sh.conf -[ -r ~/.telegram.sh ] && source ~/.telegram.sh - -[ -z "$TOKEN" ] && TOKEN=$TELEGRAM_TOKEN -[ ${#CHATS[@]} -eq 0 ] && CHATS=($TELEGRAM_CHAT) -[ -n "$TELEGRAM_DISABLE_WEB_PAGE_PREVIEW" ] && DISABLE_WEB_PAGE_PREVIEW="$TELEGRAM_DISABLE_WEB_PAGE_PREVIEW" -[ -n "$TELEGRAM_DISABLE_NOTIFICATION" ] && DISABLE_NOTIFICATION="$TELEGRAM_DISABLE_NOTIFICATION" - -log "TOKEN is now $TOKEN" -log "CHATS is now ${CHATS[*]}" -log "DISABLE_WEB_PAGE_PREVIEW is now $DISABLE_WEB_PAGE_PREVIEW" -log "DISABLE_NOTIFICATION is now $DISABLE_NOTIFICATION" - -if [ -z "$TOKEN" ]; then - echo "No bot token was given." - exit 1 -fi - -if [ ${#CHATS[@]} -eq 0 ] && [ -z "$ACTION" ]; then - echo "No chat(s) given." - exit 1 -fi - -if [ "$ACTION" = "list_chats" ]; then - list_chats - exit 0 -fi - -if [ "$ACTION" = "receive_file" ]; then - receive_file - exit 0 -fi - -shift $((OPTIND - 1)) -TEXT="$1" -log "Text: $TEXT" - -[ "$TEXT" = "-" ] && TEXT=$(\ -\nUsage: add's lydia auto chat request in the chat.\ -\n\n.remcf \ -\nUsage: remove's lydia auto chat request in the chat.\ -\n\n.repcf \ -\nUsage: starts lydia repling to perticular person in the chat." -})