Skip to content

Commit

Permalink
Fixup Dockerfile, and add more help strings
Browse files Browse the repository at this point in the history
Signed-off-by: baalajimaestro <[email protected]>
  • Loading branch information
baalajimaestro committed Mar 16, 2019
2 parents 6c5b29d + d9f52a2 commit 394eab9
Show file tree
Hide file tree
Showing 16 changed files with 397 additions and 300 deletions.
1 change: 0 additions & 1 deletion Aptfile

This file was deleted.

57 changes: 46 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,64 @@ FROM alpine:3.9
#
RUN sed -e 's;^#http\(.*\)/v3.9/community;http\1/v3.9/community;g' -i /etc/apk/repositories

# Installing Python
RUN apk add --no-cache --update \
git \
bash \
libffi-dev \
openssl-dev \
bzip2-dev \
zlib-dev \
readline-dev \
sqlite-dev \
build-base

# Set Python version
ARG PYTHON_VERSION='3.8-dev'
# Set pyenv home
ARG PYENV_HOME=/root/.pyenv
# Note installing THROUGH THIS METHOD WILL DELAY DEPLOYING
# Install pyenv, then install python versions
RUN git clone --depth 1 https://github.com/pyenv/pyenv.git $PYENV_HOME && \
rm -rfv $PYENV_HOME/.git

ENV PATH $PYENV_HOME/shims:$PYENV_HOME/bin:$PATH

RUN pyenv install $PYTHON_VERSION
RUN pyenv global $PYTHON_VERSION
RUN pip install --upgrade pip && pyenv rehash

#
# Install all the required packages
#
RUN apk add --no-cache python3 \
py-pillow py-requests py-sqlalchemy py-psycopg2 \
curl neofetch git sudo gcc musl-dev postgresql postgresql-dev
RUN apk add --no-cache sqlite
RUN apk --no-cache add build-base

RUN apk add --no-cache \
py-pillow py-requests py-sqlalchemy py-psycopg2 git py-lxml \
libxslt-dev py-pip libxml2 libxml2-dev libpq postgresql-dev \
postgresql build-base linux-headers jpeg-dev \
curl neofetch git sudo gcc python-dev python3-dev \
postgresql postgresql-client php-pgsql \
musl postgresql-dev
RUN apk add --no-cache sqlite figlet

# Copy Python Requirements to /app
RUN git clone https://github.com/psycopg/psycopg2 psycopg2 \
&& cd psycopg2 \
&& python setup.py install

RUN sed -e 's;^# \(%wheel.*NOPASSWD.*\);\1;g' -i /etc/sudoers
RUN adduser userbot --disabled-password --home /home/userbot
RUN adduser userbot wheel
USER userbot
RUN mkdir /home/userbot/userbot
RUN git clone https://github.com/baalajimaestro/Telegram-UserBot userbot
WORKDIR /home/userbot/userbot
COPY ./requirements.txt /home/userbot/userbot
#
# Install requirements
#
RUN sudo pip3 install -r requirements.txt
#
# Copy bot files to /app
#
COPY . /home/userbot/userbot
RUN sudo pip3 install -U pip
RUN sudo pip3 install -r requirementsDOCKER.txt
RUN sudo chown -R userbot /home/userbot/userbot
RUN sudo chmod -R 777 /home/userbot/userbot
cmd ["python3","-m","userbot"]
CMD ["python3","-m","userbot"]
75 changes: 40 additions & 35 deletions init/CI_Test_Script.sh
Original file line number Diff line number Diff line change
@@ -1,63 +1,55 @@
#!/bin/bash
# Copyright (C) 2019 The Raphielscape Company LLC.
#
# Licensed under the Raphielscape Public License, Version 1.b (the "License");
# you may not use this file except in compliance with the License.
#
# CI Runner Script for baalajimaestro's userbot

#! /bin/sh
# We need this directive
# shellcheck disable=1090

#CI Runner Script for baalajimaestro's userbot

function colors {
blue='\033[0;34m' cyan='\033[0;36m'
yellow='\033[0;33m'
red='\033[0;31m'
nocol='\033[0m'
}
. "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"/telegram

colors;
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)"
TELEGRAM_TOKEN=${BOT_API_KEY}
export BOT_API_KEY PARSE_BRANCH PARSE_ORIGIN COMMIT_POINT TELEGRAM_TOKEN
. "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"/telegram

kickstart_pub

function get_session {
curl -sLo userbot.session $PULL_LINK
req_install() {
pip install -r requirements.txt
}

get_session() {
curl -sLo userbot.session "$PULL_LINK"
}

function test_run {
BUILD_START=$(date +"%s")
pip install -r requirements.txt
test_run() {
python3 -m userbot test
BUILD_END=$(date +"%s")
BUILD_TIME=$(date +"%Y%m%d-%T")
DIFF=$((BUILD_END - BUILD_START))
check_if_error
}

function check_if_error {
if [ $? -eq 0 ]
then
fin
else
finerr
fi
}
trap '{
STATUS=${?}
tg_senderror
finerr
}' ERR

tg_senderror() {
tg_sendinfo "Build Throwing Error(s)" \
"@baalajimaestro naaaaa"
tg_channelcast "Build Throwing Error(s)"
exit 1
"@baalajimaestro @raphielscape naaaaa"
tg_channelcast "Build Throwing Error(s)"

[ -n "${STATUS}" ] &&
exit "${STATUS}" ||
exit 1
}

tg_yay() {
tg_sendinfo "Python CI Test passed yay" \
"Haha yes"
"Haha yes"
}

# Fin Prober
Expand All @@ -67,13 +59,26 @@ fin() {
tg_channelcast "Compilation took $((DIFF / 60)) minute(s) and $((DIFF % 60)) seconds"
tg_yay
}

finerr() {
echo "My works took $((DIFF / 60)) minute(s) and $((DIFF % 60)) seconds but it's error..."
tg_sendinfo "Build took $((DIFF / 60)) minute(s) and $((DIFF % 60)) seconds" \
"but it is having error anyways xd"
"but it is having error anyways xd"
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))
fin
}

get_session
test_run
execute
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ zalgo_text>=0.6
hastebin.py>=0.2
pybase64>=0.4.0
google_images_download>=2.4.2
google-api-python-client
google_auth_oauthlib
hachoir
Pillow>=5.3.0
telegraph
Expand All @@ -17,7 +19,7 @@ gTTS>=2.0.1
googletrans>=2.4.0
spongemock
gTTS-token>=1.1.3
psycopg2-binary
psycopg2
python-dotenv
aiohttp
telethon-session-sqlalchemy>=0.2.6
25 changes: 25 additions & 0 deletions requirementsDOCKER.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
telethon>=1.6.2
requests>=2.18.4
gtts>=2.0.1
urbandict>=0.5
gsearch>=1.6.0
wikipedia>=1.4.0
speedtest-cli>=2.0.2
zalgo_text>=0.6
hastebin.py>=0.2
pybase64>=0.4.0
google_images_download>=2.4.2
google-api-python-client
google_auth_oauthlib
hachoir
Pillow>=5.3.0
telegraph
sqlalchemy>=1.2
gTTS>=2.0.1
googletrans>=2.4.0
spongemock
gTTS-token>=1.1.3
# psycopg2-binary not today bud
python-dotenv
aiohttp
telethon-session-sqlalchemy>=0.2.6
6 changes: 6 additions & 0 deletions sample_config.env
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ PM_AUTO_BAN=False
# Example: 'postgres://userbot:userbot@localhost:5432/userbot'
#
DATABASE_URL=

#
# YouTube Data API Key for .yt command
# Get from https://console.cloud.google.com
#
YOUTUBE_API_KEY=""
3 changes: 3 additions & 0 deletions userbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@

SUDO = os.environ.get("SUDO", None)

YOUTUBE_API_KEY = os.environ.get(
"YOUTUBE_API_KEY", None
)

bot = TelegramClient("userbot", API_KEY, API_HASH)

Expand Down
56 changes: 53 additions & 3 deletions userbot/modules/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,65 @@

from time import sleep

from telethon.errors import BadRequestError
from telethon.errors import (BadRequestError, ImageProcessFailedError,
PhotoCropSizeSmallError)
from telethon.errors.rpcerrorlist import UserIdInvalidError
from telethon.tl.functions.channels import EditAdminRequest, EditBannedRequest
from telethon.tl.functions.channels import (EditAdminRequest,
EditBannedRequest,
EditPhotoRequest)
from telethon.tl.types import (ChatAdminRights, ChatBannedRights,
MessageMediaDocument, MessageMediaPhoto)

from telethon.tl.types import ChatAdminRights, ChatBannedRights

from userbot import (BRAIN_CHECKER, LOGGER, LOGGER_GROUP, HELPER)
from userbot import (BRAIN_CHECKER, LOGGER, LOGGER_GROUP, HELPER, bot)
from userbot.events import register

#=================== CONSTANT ===================
PP_TOO_SMOL = "`The image is too small`"
PP_ERROR = "`Failure while processing image`"
NO_ADMIN = "`You aren't an admin!`"

CHAT_PP_CHANGED = "`Chat Picture Changed`"
CHAT_PP_ERROR = "`Some issue with updating the pic,`" \
"`maybe you aren't an admin,`" \
"`or don't have the desired rights.`"
INVALID_MEDIA = "`Invalid Extension`"
#================================================


@register(outgoing=True, pattern="^.setgrouppic$")
async def set_group_photo(gpic):
if not gpic.text[0].isalpha() and gpic.text[0] not in ("/", "#", "@", "!"):
replymsg = await gpic.get_reply_message()
chat = await gpic.get_chat()
photo = None

if not chat.admin_rights or chat.creator:
await gpic.edit(NO_ADMIN)
return

if replymsg and replymsg.media:
if isinstance(replymsg.media, MessageMediaPhoto):
photo = await bot.download_media(message=replymsg.photo)
elif "image" in replymsg.media.document.mime_type.split('/'):
photo = await bot.download_file(replymsg.media.document)
else:
await gpic.edit(INVALID_MEDIA)

if photo:
try:
await EditPhotoRequest(
gpic.chat_id,
await bot.upload_file(photo)
)
await gpic.edit(CHAT_PP_CHANGED)

except PhotoCropSizeSmallError:
await gpic.edit(PP_TOO_SMOL)
except ImageProcessFailedError:
await gpic.edit(PP_ERROR)


@register(outgoing=True, pattern="^.promote$")
async def promote(promt):
Expand Down
20 changes: 19 additions & 1 deletion userbot/modules/chatid.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Copyright (C) 2019 The Raphielscape Company LLC.
#
# Licensed under the Raphielscape Public License, Version 1.b (the "License");
# you may not use this file except in compliance with the License.


from userbot.events import register
from userbot import (BRAIN_CHECKER, LOGGER, LOGGER_GROUP, HELPER, bot)
from time import sleep

@register(outgoing=True, pattern="^.userid$")
async def chatidgetter(e):
if not e.text[0].isalpha() and e.text[0] not in ("/", "#", "@", "!"):
Expand Down Expand Up @@ -40,4 +50,12 @@ async def log(e):
else:
await e.edit("`This feature requires Logging to be enabled!`")
sleep(2)
await e.delete()
await e.delete()

HELPER.update({
"chatid" : "Fetches the current chat's ID"
})

HELPER.update({
"userid" : "Fetches the ID of the user in reply, if its a forwarded message, finds the ID for the source."
})
11 changes: 10 additions & 1 deletion userbot/modules/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,13 @@ async def endecrypt(e):
bytes(e.pattern_match.group(2), "utf-8"), validate=True
)
)[2:]
await e.reply("Decoded: `" + lething[:-1] + "`")
await e.reply("Decoded: `" + lething[:-1] + "`")


HELPER.update({
"base64" : "Find the base64 encoding of the given string"
})

HELPER.update({
"hash" : "Find the md5, sha1, sha256, sha512 of the string when written into a txt file."
})
Loading

0 comments on commit 394eab9

Please sign in to comment.