Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 8c58247

Browse files
committed
skeleton bot ready
1 parent da3eb42 commit 8c58247

File tree

7 files changed

+61
-86
lines changed

7 files changed

+61
-86
lines changed

README.md

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,6 @@
11
# API Digest 2021
2-
This repository contains the rules and code of conduct for __API Digest 2021__.
2+
The idea is to create a Telegram Bot for running the code inside Telegram, written in messages. The code has to be written in the message and the bot will return the output. The user can add its username in the bot to receive its details in messages like rating, number of stars etc.
33

4-
## Contents
5-
- __[Contents](#contents)__
6-
- __[Requirements](#requirements)__
7-
- __[Few pointers](#few-pointers)__
8-
- __[How to submit?](#how-to-submit)__
9-
- __[Rules](HackIIITV_rules_and_timeline.pdf)__
10-
- __[Code of Conduct](CODE_OF_CONDUCT.md)__
11-
- __[Our Community](#our-community)__
12-
- __[Contact / Support](#contact--support)__
4+
We will be using APIs from Codechef, Codeforces or Hackerrank to fetch a random question from any category/difficulty level.
135

14-
### Requirements
15-
16-
- __[GitHub account](https://github.com/login)__
17-
- Install __[git](https://git-scm.com/)__ for your repsective OS.
18-
- Make sure you are part of IIITV organisation on GitHub, else join __[here](http://getmein.glitch.me/)__
19-
20-
### Few pointers
21-
22-
- You can make at max one commit per hour.
23-
- Don't close your PR.
24-
- No commits after Hackathon ends will be entertained.
25-
- It is required from the teams to keep committing within __three__ hours of the previous commit to keep your hack backed up.
26-
- Make sure your whole project is inside the folder of your team.
27-
- If you have time left, make sure you make a README.md 📄 😉(it will help others to understand your code)
28-
29-
### How to submit?
30-
31-
One member from each team have to follow this instructions:
32-
Follow the instructions in order:
33-
34-
1. Fork this repository.
35-
36-
2. Clone your fork, using
37-
`git clone https://github.com/<your-username>/api-digest-2021.git`
38-
39-
3. Change Directory to `api-digest-2021`, using
40-
`cd api-digest-2021`
41-
42-
4. Set remote to original repository using
43-
`git remote add ups https://github.com/iiitv/api-digest-2021.git`
44-
45-
5. Create a branch named `team#x`, where __"x"__ is your team number, using
46-
`git checkout -b team#x`
47-
48-
6. Add a folder with name `team#x - {Chosen_Theme_number}` in root directory. Make sure your whole hack is in folder `team#x - {Chosen_Theme_number}`.
49-
50-
7. Now add this folder to your staging area, using
51-
`git add "team#x - {Chosen_Theme_number}"`
52-
53-
8. Now commit the changes using,
54-
`git commit -m "Add team#x"`
55-
56-
9. Push the changes using,
57-
`git push`
58-
59-
10. Open a pull request: As soon as the changes will be pushed, GUI of repository's main page will show a yellow banner saying you too open a Pull request, just click on it and you are done.
60-
61-
For making changes to PR, just keep on repeating Step 6-9.
62-
63-
### Rules
64-
65-
- Keep your content as original as possible.
66-
- It is allowed to use available softwares/packages as a module, but they can't be your project.
67-
68-
### Contact / Support
69-
70-
- Write to us at: __[[email protected]](mailto:[email protected])__
71-
- Join the discord server: __[Technical Committee](https://discord.gg/Rw4X9rYZgR)__
72-
73-
### Our Community
74-
75-
- Open source projects created by students at IIITV : [IIITV Open Source Org](https://github.com/iiitv)
76-
- Discord channel where we discuss topics related to DSA and Competitive Programming: [IIITVCC Discord Server Invite](https://discord.gg/pUPbVHF)
77-
- Join the Open Source Org and our Slack Channel to ask your doubts and discussion: [Get Me In](https://getmein.glitch.me/), [Slack](https://join.slack.com/t/iiitvadodara/shared_invite/zt-gx92qvc2-X_NREKMxP6f7DlyZuxzM_g)
78-
79-
### Happy Hacking! 🖖
80-
81-
***
82-
83-
<p align='center'>Made With ❤️ By <a href="https://github.com/iiitv">Team API Digest</a></p>
6+
Further, we will try to introduce more features like fetching a random question daily according to user's rating, alert about the upcoming contests and solving language specific ladders.

__pycache__/admins.cpython-39.pyc

1.32 KB
Binary file not shown.

team#17-education/README.md

Lines changed: 0 additions & 6 deletions
This file was deleted.
1.33 KB
Binary file not shown.

team#17-education/admins.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import requests
2+
import json
3+
import configparser as cfg
4+
5+
class CS_toolkit():
6+
7+
def __init__(self, config):
8+
self.token = self.read_token_from_config_file(config)
9+
self.base = "https://api.telegram.org/bot{}/".format(self.token)
10+
11+
def getUpdates(self, offset=None):
12+
url = self.base + "getUpdates?timeout=100" #Timeout = 100 to avoid requesting endpoint again and again
13+
if offset:
14+
url += "&offset={}".format(offset + 1)
15+
16+
r = requests.get(url)
17+
return json.loads(r.content)
18+
19+
def sendMessage(self, msg, chat_id):
20+
url = self.base + "sendMessage?chat_id={}&text={}".format(chat_id, msg)
21+
if msg is not None:
22+
requests.get(url)
23+
24+
def read_token_from_config_file(self, config):
25+
parser = cfg.ConfigParser()
26+
parser.read(config)
27+
return parser.get('creds', 'token')

team#17-education/config.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[creds]
2+
token = 1651920399:AAHrId7JydTx9O4boUEx__MdWt8ZcVbmKNs

team#17-education/server.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from admins import CS_toolkit
2+
3+
4+
bot = CS_toolkit("config.cfg")
5+
6+
7+
def reply(msg):
8+
if msg == "/start":
9+
return "This is your one-stop bot for all CS related things.\nType /help to see all commands."
10+
if msg is None:
11+
return
12+
if msg is not None:
13+
return "Okay!"
14+
15+
update_id = None
16+
while True:
17+
updates = bot.getUpdates(offset=update_id)
18+
updates = updates["result"]
19+
if updates:
20+
for item in updates:
21+
update_id = item["update_id"]
22+
try:
23+
msg = item["message"]["text"]
24+
sender = item["message"]["from"]["id"]
25+
except:
26+
msg = None
27+
sender = None
28+
reply_msg = reply(msg)
29+
bot.sendMessage(reply_msg, sender)

0 commit comments

Comments
 (0)