Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ak committed Aug 3, 2023
0 parents commit 35023a7
Show file tree
Hide file tree
Showing 28 changed files with 22,532 additions and 0 deletions.
106 changes: 106 additions & 0 deletions MainWindow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(846, 617)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.widget_2 = QtWidgets.QWidget(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.widget_2.sizePolicy().hasHeightForWidth())
self.widget_2.setSizePolicy(sizePolicy)
self.widget_2.setObjectName("widget_2")
self.verticalLayout = QtWidgets.QVBoxLayout(self.widget_2)
self.verticalLayout.setObjectName("verticalLayout")
self.widget = QtWidgets.QWidget(self.widget_2)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.widget.sizePolicy().hasHeightForWidth())
self.widget.setSizePolicy(sizePolicy)
self.widget.setObjectName("widget")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.widget)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label = QtWidgets.QLabel(self.widget)
self.label.setObjectName("label")
self.horizontalLayout_2.addWidget(self.label)
self.token_input = QtWidgets.QLineEdit(self.widget)
self.token_input.setObjectName("token_input")
self.horizontalLayout_2.addWidget(self.token_input)
self.test_btn = QtWidgets.QPushButton(self.widget)
self.test_btn.setObjectName("test_btn")
self.horizontalLayout_2.addWidget(self.test_btn)
self.verticalLayout.addWidget(self.widget)
self.widget_3 = QtWidgets.QWidget(self.widget_2)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.widget_3.sizePolicy().hasHeightForWidth())
self.widget_3.setSizePolicy(sizePolicy)
self.widget_3.setObjectName("widget_3")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget_3)
self.horizontalLayout.setObjectName("horizontalLayout")
self.stop_btn = QtWidgets.QPushButton(self.widget_3)
self.stop_btn.setObjectName("stop_btn")
self.horizontalLayout.addWidget(self.stop_btn)
self.start_btn = QtWidgets.QPushButton(self.widget_3)
self.start_btn.setObjectName("start_btn")
self.horizontalLayout.addWidget(self.start_btn)
self.verticalLayout.addWidget(self.widget_3, 0, QtCore.Qt.AlignRight)
self.verticalLayout_3.addWidget(self.widget_2)
self.widget_4 = QtWidgets.QWidget(self.centralwidget)
self.widget_4.setObjectName("widget_4")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.widget_4)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.tableView = QtWidgets.QTableView(self.widget_4)
self.tableView.setObjectName("tableView")
self.tableView.horizontalHeader().setCascadingSectionResizes(True)
self.verticalLayout_2.addWidget(self.tableView)
self.widget_5 = QtWidgets.QWidget(self.widget_4)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.widget_5.sizePolicy().hasHeightForWidth())
self.widget_5.setSizePolicy(sizePolicy)
self.widget_5.setObjectName("widget_5")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.widget_5)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.clear_all_btn = QtWidgets.QPushButton(self.widget_5)
self.clear_all_btn.setObjectName("clear_all_btn")
self.horizontalLayout_3.addWidget(self.clear_all_btn)
self.delete_btn = QtWidgets.QPushButton(self.widget_5)
self.delete_btn.setObjectName("delete_btn")
self.horizontalLayout_3.addWidget(self.delete_btn)
self.add_btn = QtWidgets.QPushButton(self.widget_5)
self.add_btn.setObjectName("add_btn")
self.horizontalLayout_3.addWidget(self.add_btn)
self.verticalLayout_2.addWidget(self.widget_5, 0, QtCore.Qt.AlignRight)
self.verticalLayout_3.addWidget(self.widget_4)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 846, 20))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label.setText(_translate("MainWindow", "Token"))
self.test_btn.setText(_translate("MainWindow", "Test"))
self.stop_btn.setText(_translate("MainWindow", "Stop"))
self.start_btn.setText(_translate("MainWindow", "Start"))
self.clear_all_btn.setText(_translate("MainWindow", "Clear All"))
self.delete_btn.setText(_translate("MainWindow", "Delete"))
self.add_btn.setText(_translate("MainWindow", "Add"))
128 changes: 128 additions & 0 deletions Process_handling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# import for GUI signals and threads
from PyQt5.QtCore import QRunnable, QThreadPool,QThread,pyqtSignal,QObject,pyqtSlot
import threading
# Import for telegram bot and async code usage
import asyncio
from aiogram import Bot, Dispatcher, executor, types
from aiogram.utils import executor
import re
# SQLite database imports
import sqlite3

# Making bot code

async def bot_main(token,status):
bot = Bot(token)
dp = Dispatcher(bot)
try:
# Use the 'get_me' method to check if the token is valid
me = await bot.get_me()
print("Bot information:", me)
print("Token is valid!")
mydict = me.__dict__["_values"]
mydict['status'] = True
print(mydict)
status.emit(mydict)
except Exception as e:
print("Token is invalid:", e)
mydict = {"status":False,"message":str(e)}
status.emit(mydict)
finally:
# Close the bot session gracefully
await dp.storage.close()
await dp.storage.wait_closed()
session = await bot.get_session()
await session.close()
return True

class Test_Bot(QThread):
status = pyqtSignal(dict)
def __init__(self,token):
super().__init__()
self.token = token

def run(self):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(bot_main(self.token,self.status))
return







class AIogramBot(QThread):
stopped = pyqtSignal(bool)
started = pyqtSignal()
error = pyqtSignal(str)
def __init__(self,token,bot_started_signal: pyqtSignal):
super().__init__()
try:
self.bot = Bot(token=token)
self.dp = Dispatcher(self.bot)
self.bot_started_signal = bot_started_signal
except Exception as error:
print(error)
self.error.emit(str(error))
raise error

@self.dp.message_handler()
async def get_messages(message: types.Message):
try:
db = sqlite3.connect("information.db")
cursor = db.cursor()
cursor.execute("SELECT * FROM messages")
rows = cursor.fetchall()
for row in rows:
if row[2] != "" and row[2] != None:
if row[4] == 0:
print("checking in lowercase : ",message.text.lower()," | ",row[2].lower())
if message.text.lower() == row[2].lower():
await message.reply(row[1])
break
else:
if message.text == row[2]:
await message.reply(row[1])
break
elif row[3] != "" and row[3] != None:
if row[4] == 0:
matches = re.findall(row[3],message.text,re.IGNORECASE)
else:
matches = re.findall(row[3],message.text)
if len(matches)>0:
await message.reply(row[1])
break
cursor.close()
db.close()
except sqlite3.Error as e:
print(f"Error occurred: {e}")
async def started_signal(self,dp):
self.started.emit()
self.bot_started_signal.emit(True)
def start_bot(self):
try:
print("bot starting...")
executor.start_polling(dispatcher=self.dp,skip_updates=True,on_startup=self.started_signal)
except Exception as error:
print(error)
self.error.emit(str(error))
return

def run(self):
try:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
self.start_bot()
except Exception as error:
print(error)
self.error.emit(str(error))
return

def stop_bot(self):
self.terminate()
self.wait()
print("bot is stopped")
self.stopped.emit(True)
self.bot_started_signal.emit(False)
109 changes: 109 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<p align="center">
<img width=100 height=100 src="logo.png">
</p>

# __ReplyBot - Telegram Bot for Automated Replies (GUI and System Tray Support)__
ReplyBot is a user-friendly Telegram bot with a Graphical User Interface (GUI) that allows you to automate responses based on predefined rules. Additionally, it provides compiled executables for Linux, Mac, and Windows, and the bot can be minimized to the system tray and run in the background without displaying the GUI.

## __Features__:
+ __Automated Replies__: ReplyBot can instantly respond to incoming messages without the need for manual intervention, saving you time and effort.

+ __Keyword-Based Replies__: You can define specific keywords or phrases to trigger automated responses, ensuring that your bot responds appropriately to relevant messages.

+ __Regular Expression (Regex) Support__: Utilize the power of regular expressions to create more flexible and dynamic response rules, enabling complex matching patterns.

+ __Case-Sensitive Matching__: Choose whether the bot should consider the case when matching keywords or patterns.

+ __Case-Insensitive Matching__: Optionally, you can enable case-insensitive matching to make the bot respond to messages regardless of letter case.

+ __GUI Interface__: Interact with the bot using a friendly and intuitive Graphical User Interface.

+ __System Tray Support__: ReplyBot can be minimized to the system tray, running silently in the background without cluttering your taskbar.

+ __Cross-Platform Compatibility__: Executables are available for Linux, Mac, and Windows operating systems.

## __Prerequisites__
- Python 3.7 or higher
- It's made on Python 3.9.2
- __telegram__ account is also required to get bot token


## __Getting Started__
To use **ReplyBot**, follow these steps:

**Using Executables**:
1. __Download Executables__:
+ Go to the [Release Page](https://github.com/AKRASH-Nadeem/ReplyBot/releases) and download the appropriate executable for your operating system (Linux, Mac, or Windows).
![Executable file](ScreenShot/1.png)
2. __Create a Telegram Bot__:
+ Talk to the BotFather on Telegram to create a new bot and obtain the API token.

<p align="center">
<img src="ScreenShot/0.png" alt="Telegram bot token">
</p>

3. __Configure the Bot__:
+ Launch the ReplyBot executable.
+ Enter your Telegram Bot API token in the provided field And Click on Test Button.
![Enter Token](ScreenShot/3.png)

+ Check the __Token is valid__ and ready to be used.Click on __Save__ button if token is __valid__ and __Active__.
![Connection Test](ScreenShot/4.png)

4. __Add Reply__:

+ Click on __Add__ button to add reply messages And __Save__ it.
![Add Reply Messages](ScreenShot/5.png)
5. __Start Bot__:
+ Start the bot By clicking the Start button.
![Start Bot](ScreenShot/6.png)
6. __Check the bot working__:
+ Message your bot and see if it works.You can open issue if there is any.
<p align="center">
<img src="ScreenShot/7.png" alt="Test Bot">
</p>

## __Stop Bot__
![Stop Bot](ScreenShot/8.png)

## __Delete the reply__:
+ Select a row and click on delete button
<p align="center">
<img src="ScreenShot/9.png" alt="Delete Reply">
</p>

## __System Tray Support__
ReplyBot can be minimized to the system tray by Closing it, running silently in the background without cluttering your taskbar.
<br>
![System Tray Message](ScreenShot/System_tray.png)

You can see the __icon__ of the bot in __System Tray__ of windows

![System Tray Icon](ScreenShot/system_tray_icon.png)

## __Quit__
To Quit the Bot you need to __quit__ it from the __system tray__ menu
<div>
<img src="ScreenShot/System_tray_options.png" alt="System Tray options">
</div>

## __Get Source Code__

```
git clone https://github.com/your-username/replybot.git
cd replybot
```
## Install requirements
```
pip install -r requirements.txt
```
## Run the Bot
```
python main.py
```

# __Contributing__
Contributions to ReplyBot are welcome! If you have suggestions, bug fixes, or new features to add, feel free to create a pull request.

# __Disclaimer__
ReplyBot is provided as-is without any warranties. Please use it responsibly and adhere to Telegram's guidelines and terms of service.
Binary file added ScreenShot/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenShot/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenShot/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenShot/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenShot/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenShot/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenShot/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenShot/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenShot/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenShot/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenShot/System_tray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenShot/System_tray_options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenShot/system_tray_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 35023a7

Please sign in to comment.