Skip to content

Commit

Permalink
Start message editing
Browse files Browse the repository at this point in the history
  • Loading branch information
respasha committed Jul 22, 2016
1 parent 61230fc commit 6de4b7b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@
* [Contact](#contact)

##ChangeLog!
####Version1.1
* **Major Update**: Start Message editing by `/setstartmessage`
Start message is the fist message user sees, when he/she starts the bot.
* **Bugs in this version**: Hopefully no

####Version1.0
* **Major Update**:
1. All storing data functionality moved to MongoDB.
2. Added paging to users list and blocked list.
3. Simplified user blocking using inline keyboards.
4. Code refactored and beautified.
* **Bugs in this version** : Hopefully no
* **Bugs in this version**: Hopefully no



Expand All @@ -46,6 +51,7 @@
* Start bot: `bash launch.sh`

## What's new ???
* You can now set Start Message the same way you do with the Block Message and Unavailable Message. New commands are `/setstartmessage` and `/viewstartmessage`
* Bot sends _usercard_ with each user's message (which increases the number of messages, i know. I hope, I'll get to it later). _Usercard_ shows all info about user. Ream more about blocking and unblocking [here](#blocking-and-unblocking-feature).
* Admins can set their status as `/available` or `/unavailable`. This means that when you will not be available bot will notify the user if he/she tries to text you by sending him your unavailable message, just like the way you have a pre-recorded message on answering machines! The bot will however forward you the message. You can set and view your unavailable message by typing `/setunavailablemessage` and `/setunavailablemessage` respectively.
* You can now view the list of all users bot has seen! Type `/viewuserslist`. The list will contain basic info about every user and a command to their usercard.
Expand All @@ -64,6 +70,10 @@ The idea of this bot is pretty simple: you just place the bot between you and th

<p align="center">![Screenshot](http://i.imgur.com/YZoiTjd.png)

#### Setting Start Message
You can set Start Message -- the message, which user sees when he/she starts the bot.
Use `/setstartmessage` command for setting it and `/viewstartmessage` for viewing it.

### Blocking and Unblocking Feature
It was messy and complicated for me in Mr_Gigabyte's implementation, so I've fully rewrited it.

Expand Down
19 changes: 15 additions & 4 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ def __init__(self, coll):
self.data = {
'availability': 'available',
'blockmsg': "uh..oh you're blocked",
'nonavailmsg': "I'm sorry i'm apparently offline"
'nonavailmsg': "I'm sorry i'm apparently offline",
'startmsg': " Write me your text and the admin will get in touch with you shortly."
}
result = self.coll.insert_one(self.data)
self.data['_id'] = result.inserted_id

@property
def availability(self):
return self.data['availability']
return self.data.get('availability') or ''

@availability.setter
def availability(self, value):
Expand All @@ -83,7 +84,7 @@ def availability(self, value):

@property
def blockmsg(self):
return self.data['blockmsg']
return self.data.get('blockmsg') or ''

@blockmsg.setter
def blockmsg(self, value):
Expand All @@ -92,14 +93,24 @@ def blockmsg(self, value):

@property
def nonavailmsg(self):
return self.data['nonavailmsg']
return self.data.get('nonavailmsg') or ''

@nonavailmsg.setter
def nonavailmsg(self, value):
self.data['nonavailmsg'] = value
self.coll.update_one({'_id': self.data['_id']}, {'$set': self.data})


@property
def startmsg(self):
return self.data.get('startmsg')

@startmsg.setter
def startmsg(self, value):
self.data['startmsg'] = value
self.coll.update_one({'_id': self.data['_id']}, {'$set': self.data})


__db_client = MongoClient(config.db_auth)
__db = __db_client[config.db_name]

Expand Down
52 changes: 47 additions & 5 deletions proxy_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ def command_help(message):
`6`- /viewblockmessage: to view the block message (that the users will see)
`7`- /setblockmessage : set the text message that you want users to see when they are blocked
`8`- /viewblocklist : allows you to view the list of blocked users
`9`- /viewuserlist : allows you to view all non-blocked users in database\n
`9`- /viewuserlist : allows you to view all non-blocked users in database
`10`- /setstartmessage : set the text message that you want users to see when they start the bot
`11`- /viewstartmessage : to view the Start Message
\n
*For any help and queries please contact -* [me](telegram.me/phash_bot) *or check out* [source code](https://github.com/p-hash/proxybot)""",
parse_mode="Markdown"
)
Expand All @@ -98,7 +101,7 @@ def command_viewblockmessage(message):
)


# command for admin to set the block message that the user after getting blocked
# command for admin to set the block message that the user see after getting blocked
@bot.message_handler(func=lambda message: message.chat.id == config.my_id, commands=["setblockmessage"])
def command_setblockmessage(message):
blockmsg = bot.send_message(
Expand All @@ -119,6 +122,46 @@ def save_blockmsg(message):
)


# command for admin: Used to view the start message
@bot.message_handler(func=lambda message: message.chat.id == config.my_id, commands=["viewstartmessage"])
def command_viewstartmessage(message):
if not db.common.startmsg:
bot.send_message(
message.chat.id,
"""*Oops!*
You haven't set any *Start Message* for the users.
To set one kindly send: /setstartmessage to me""",
parse_mode="Markdown"
)
else:
bot.send_message(
message.chat.id,
"`Your Start Message:`" + "\n" + db.common.startmsg,
parse_mode="Markdown"
)


# command for admin to set the start message that the user see when he starts the bot
@bot.message_handler(func=lambda message: message.chat.id == config.my_id, commands=["setstartmessage"])
def command_setstartmessage(message):
startmsg = bot.send_message(
message.chat.id,
"Alright now send me your text that you want the user to see when he/she *starts* the bot",
parse_mode="Markdown"
)
bot.register_next_step_handler(startmsg, save_startmsg)


# Next step handler for saving blockmsg
def save_startmsg(message):
db.common.startmsg = str(message.text)
bot.reply_to(
message,
"Thanks! " + "\n" + "*The new Start Message has been set successfully* ",
parse_mode="Markdown"
)


# command for admin
# view the whole Block List containing usernames and nicknames of the blocked users, refer config.py for more info
@bot.message_handler(func=lambda message: message.chat.id == config.my_id, commands=["viewblocklist"])
Expand Down Expand Up @@ -268,7 +311,7 @@ def save_nonavailmsg(message):
db.common.nonavailmsg = str(message.text)
bot.reply_to(
message,
"Thanks! " + "\n" + "*The new NonAvailable Message has been set successfully* ",
"Thanks! " + "\n" + "*The new Unavailable Message has been set successfully* ",
parse_mode="Markdown"
)

Expand Down Expand Up @@ -320,8 +363,7 @@ def command_checkstatus(message):
def command_start_all(message):
bot.send_message(
message.chat.id,
"Hey " + message.chat.first_name + "!" + "\n" +
" Write me your text and the admin will get in touch with you shortly."
"Hey " + message.chat.first_name + "!\n" + db.common.startmsg
)


Expand Down

0 comments on commit 6de4b7b

Please sign in to comment.