Skip to content

Commit

Permalink
LilSholex 5.4
Browse files Browse the repository at this point in the history
- Updated Python Packages
- Updated to Python 3.10.4
- Updated to Nginx 1.21.6, OpenSSL 3.0.2
- Updated memcached, rabbitmq and MySQL
- Updated setup instruction
- Updated help messages
- Fixed some small bugs
  • Loading branch information
RealNitroZeus committed Apr 23, 2022
1 parent 30d5724 commit 6eef65c
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 124 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10.1
FROM python:3.10.4
# Addding requirements
COPY requirements.txt requirements.txt
RUN pip install -U pip && pip install -r requirements.txt --no-cache-dir
Expand Down
4 changes: 2 additions & 2 deletions Nginx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:impish
ARG NGINX_VERSION=nginx-1.21.5
ARG OPENSSL_VERSION=openssl-3.0.1
ARG NGINX_VERSION=nginx-1.21.6
ARG OPENSSL_VERSION=openssl-3.0.2
# Compiling
RUN apt update && DEBIAN_FRONTEND="noninteractive" apt install -y build-essential \
libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev python3.9 python3-pip wget \
Expand Down
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
# Little Sholex
A Project Containing Telegram API bots and small web apps .
# Included Projects
- [Persian Meme](http://t.me/Persian_Meme_Bot)
- [Persian Meme](https://t.me/Persian_Meme_Bot)
# Usage
1. Install Docker
2. Create a swarm
3. Create these swarm secrets :
- persianmeme_token : Persian Meme Telegram API token
- persianmeme_channel : Persian Meme voting channel ID
- secret_key : Django secret key
- db_password : Database password
- persianmeme_anim : Persian Meme help GIF file ID
- persianmeme_logs : Persian Meme logging channel ID
- persianmeme_messages : Use anything not complete yet :)
- ssl_certificate : SSL certificate
- ssl_key : SSL private key
- dhparam : SSL dhparam
- domain : Your Domain
- persianmeme_help_messages : A JSON file containing help messages and animations
3. Create these docker swarm secrets:
- `persianmeme_token`: Persian Meme Telegram API token
- `persianmeme_channel`: Persian Meme voting channel ID
- `secret_key`: Django secret key
- `db_password`: Database password
- `persianmeme_anim`: Persian Meme help GIF file ID
- `persianmeme_logs`: Persian Meme logging channel ID
- `persianmeme_messages`: "Contact Admin" archive channel ID
- `persianmeme_reports`: Meme Report archive channel ID
- `ssl_certificate`: SSL certificate
- `ssl_key`: SSL private key
- `dhparam`: SSL dhparam
- `domain`: Your Domain
- `persianmeme_help_messages`: A JSON file containing help messages and animations
4. Replace {persianmeme_token} & {domain} inside conf/nginx.conf with
your domain and bot token
5. `docker stack deploy -c docker-compose.yml {stack name}`

**Swarm health checks are included and containers will get replaced after running into a problem !**

**If you have any questions about docker swarm or secrets checkout Docker official documentation about
Docker swarm secrets : https://docs.docker.com/engine/swarm/secrets/**
- In order to update your stack use this command :
Docker swarm secrets: https://docs.docker.com/engine/swarm/secrets/**
- In order to update your stack use this command:

`docker stack deploy -c docker-compose.yml {stack name}`
# Developers
Created by NitroZeus and RezFD

Telegram : https://t.me/SholexTeam
GitLab : https://gitlab.com/nitrozeus
GitLab : https://gitlab.com/RezFD
Created by NitroZeus and RezFD
- Telegram: [@SholexTeam](https://t.me/SholexTeam)
- GitHub: [@RealNitroZeus](https://github.com/RealNitroZeus) - [@RezFD](https://github.com/RezFD)
- Email: [NitroZeus](mailto:[email protected]) - [RezFD](mailto:[email protected])

SholexTeam ®
20 changes: 10 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.8"
services:
db:
image: mysql:8.0.27
image: mysql:8.0.28
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD_FILE: "/run/secrets/db_password"
Expand Down Expand Up @@ -48,7 +48,7 @@ services:
- source: mysql
target: /etc/mysql/conf.d/mysql.cnf
rabbitmq:
image: rabbitmq:3.9.12
image: rabbitmq:3.9.15
healthcheck:
test: "rabbitmq-diagnostics -q ping"
interval: 30s
Expand Down Expand Up @@ -87,7 +87,7 @@ services:
- source: rabbitmq
target: /etc/rabbitmq/rabbitmq.conf
nginx:
image: ghcr.io/sholex-team/nginx:3.8
image: ghcr.io/sholex-team/nginx:3.9
networks:
- nginx_lilsholex
- internet
Expand All @@ -101,7 +101,7 @@ services:
- gunicorn
- daphne
volumes:
- ./lilsholex-dev/static:/root/lilsholex/static:ro
- ./static:/root/lilsholex/static:ro
- type: volume
source: nginx
target: /var/log/nginx
Expand Down Expand Up @@ -137,7 +137,7 @@ services:
- "443:443/tcp"
- "80:80/tcp"
lilsholex:
image: ghcr.io/sholex-team/lilsholex:5.3
image: ghcr.io/sholex-team/lilsholex:5.4
networks:
- db_django
- nginx_lilsholex
Expand Down Expand Up @@ -189,7 +189,7 @@ services:
window: 10s
delay: 5s
celery: &celery_base
image: ghcr.io/sholex-team/lilsholex-dev:6.1.5
image: ghcr.io/sholex-team/lilsholex:5.4
command: "celery -A LilSholex worker -Q celery -l info -c 2 -E"
networks:
- db_django
Expand Down Expand Up @@ -246,7 +246,7 @@ services:
environment:
FLOWER_BASIC_AUTH: "sholex:flower_password"
lilsholex_broadcasts:
image: ghcr.io/sholex-team/lilsholex:5.3
image: ghcr.io/sholex-team/lilsholex:5.4
command: "python manage.py process_broadcasts"
networks:
- db_django
Expand Down Expand Up @@ -288,7 +288,7 @@ services:
window: 10s
delay: 5s
memcached:
image: memcached:1.6.12
image: memcached:1.6.15
command: "memcached -m 256"
networks:
- cache_django
Expand Down Expand Up @@ -317,7 +317,7 @@ services:
monitor: 10s
order: start-first
lilsholex_migrations:
image: ghcr.io/sholex-team/lilsholex:5.3
image: ghcr.io/sholex-team/lilsholex:5.4
command: "bash -c 'yes | python manage.py makemigrations persianmeme && \
yes | python manage.py migrate && python manage.py collectstatic --noinput'"
secrets:
Expand Down Expand Up @@ -406,7 +406,7 @@ secrets:
persianmeme_reports:
external: true
persianmeme_help_messages:
file: lilsholex-dev/secrets/help_messages.json # Replace file_id of animations.
file: ./secrets/help_messages.json # Replace file_id of animations.
secret_key:
external: true
ssl_certificate:
Expand Down
5 changes: 1 addition & 4 deletions persianmeme/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ def unban_user(self, request: HttpRequest, queryset):
class Meme(admin.ModelAdmin):
@admin.display(description='Accept Votes')
def accept_vote(self, request: HttpRequest, queryset):
result = [
(target_meme, target_meme.accept(), target_meme.delete_vote())
for target_meme in queryset if target_meme.status == 'p'
]
result = [(target_meme, target_meme.accept()) for target_meme in queryset if target_meme.status == 'p']
result_len = len(result)
if result_len == 0:
self.message_user(request, 'There is no need to accept these memes !')
Expand Down
9 changes: 7 additions & 2 deletions persianmeme/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,18 @@ def delete_message(self, message_id: int):

@sync_fix
def copy_message(
self, message_id: int, reply_markup: dict = '', from_chat_id: int = None, chat_id: int = None
self,
message_id: int,
reply_markup: dict = '',
from_chat_id: int = None,
chat_id: int = None,
protect_content: bool = False
):
assert (chat_id and not from_chat_id) or (from_chat_id and not chat_id),\
'You must use a chat_id or a from_chat_id !'
if reply_markup:
reply_markup = json.dumps(reply_markup)
base_param = {'message_id': message_id, 'reply_markup': reply_markup}
base_param = {'message_id': message_id, 'reply_markup': reply_markup, 'protect_content': protect_content}
with self.session.get(
f'{self._BASE_URL}copyMessage',
params={
Expand Down
13 changes: 5 additions & 8 deletions persianmeme/handlers/callback_query/menus/rating.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from persianmeme.classes import User
from LilSholex.exceptions import RequestInterruption
from django.db.models import F
from persianmeme.translations import user_messages


def handler(rate_option: str, meme_id: id, query_id: str, answer_query, inliner: User):
Expand All @@ -12,21 +13,17 @@ def handler(rate_option: str, meme_id: id, query_id: str, answer_query, inliner:
raise RequestInterruption()
if rate_option == 'up':
if meme.voters.filter(user_id=inliner.database.user_id).exists():
answer_query(query_id, inliner.translate(
'voted_before', inliner.translate(meme.type_string)
), True)
answer_query(query_id, user_messages['voted_before'].format(user_messages[meme.type_string]), True)
else:
inliner.add_voter(meme)
meme.votes = F('votes') + 1
meme.save()
answer_query(query_id, inliner.translate(
'meme_voted', inliner.translate(meme.type_string)
), False)
answer_query(query_id, user_messages['meme_voted'].format(user_messages[meme.type_string]), False)
else:
if meme.voters.filter(user_id=inliner.database.user_id).exists():
inliner.remove_voter(meme)
meme.votes = F('votes') - 1
meme.save()
answer_query(query_id, inliner.translate('took_vote_back'), False)
answer_query(query_id, user_messages['took_vote_back'], False)
else:
answer_query(query_id, inliner.translate('not_voted'), True)
answer_query(query_id, user_messages['not_voted'], True)
21 changes: 16 additions & 5 deletions persianmeme/handlers/callback_query/menus/voting.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
from persianmeme.models import Meme
from persianmeme.models import Meme, BOT_ADMINS, User
from LilSholex.exceptions import RequestInterruption
from persianmeme.classes import User
from persianmeme.translations import admin_messages
from persianmeme.classes import User as UserClass


def handler(vote_option: str, query_id: str, meme_id: int, answer_query, inliner: User):
def handler(vote_option: str, query_id: str, meme_id: int, answer_query, inliner: UserClass):
try:
meme = Meme.objects.get(id=meme_id, status=Meme.Status.PENDING)
except Meme.DoesNotExist:
raise RequestInterruption()
match vote_option:
case 'a':
if not inliner.like_meme(meme):
if inliner.database.rank in BOT_ADMINS and inliner.database.menu == User.Menu.ADMIN_GOD_MODE:
answer_query(
query_id, admin_messages['admin_meme_accepted'].format(admin_messages[meme.type_string]), True
)
meme.accept(inliner.session)
elif not inliner.like_meme(meme):
answer_query(query_id, inliner.translate('vote_before', inliner.translate(
meme.type_string
)), True)
else:
answer_query(query_id, inliner.translate('voted'), False)
case 'd':
if not inliner.dislike_meme(meme):
if inliner.database.rank in BOT_ADMINS and inliner.database.menu == User.Menu.ADMIN_GOD_MODE:
answer_query(
query_id, admin_messages['admin_meme_denied'].format(admin_messages[meme.type_string]), True
)
meme.deny(inliner.session)
elif not inliner.dislike_meme(meme):
answer_query(query_id, inliner.translate('vote_before', inliner.translate(
meme.type_string
)), True)
Expand Down
6 changes: 0 additions & 6 deletions persianmeme/handlers/message/menus/admin/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
edit_ad_id,
edit_ad,
ban_vote,
deny_meme,
accept_meme,
send_edit_meme,
file_id,
edit_meme_name,
Expand Down Expand Up @@ -67,10 +65,6 @@ def handler(message: dict, text: str, message_id: int, user: UserClass):
edit_ad.handler(message_id, user)
case User.Menu.ADMIN_BAN_VOTE if target_vote := user.get_vote(message):
ban_vote.handler(target_vote, user)
case User.Menu.ADMIN_DENY_MEME if target_meme := user.get_vote(message):
deny_meme.handler(target_meme, user)
case User.Menu.ADMIN_ACCEPT_MEME if target_meme := user.get_vote(message):
accept_meme.handler(target_meme, user)
case User.Menu.ADMIN_SEND_EDIT_MEME if target_meme := user.get_public_meme(message):
send_edit_meme.handler(target_meme, user)
case User.Menu.ADMIN_EDIT_MEME:
Expand Down
Loading

0 comments on commit 6eef65c

Please sign in to comment.