Skip to content

Commit ab004a1

Browse files
committed
added a temporary toxicity checker and $contributors command
1 parent 9b06484 commit ab004a1

5 files changed

Lines changed: 61 additions & 24 deletions

File tree

README.md

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
# Chintubot
22
### Prefix - $
3-
### Memes
4-
```
5-
csmeme
6-
```
7-
### GitHub
8-
```
9-
gituser, gitmember
10-
repos, repositories, github
11-
```
12-
### Google
13-
```
14-
gsearch
15-
```
16-
### Moderation
17-
```
18-
ban
19-
kick
20-
mute
21-
removewarn
22-
unmute
23-
warn
24-
warns
25-
```
3+
4+
### Type "$help" to get the list of commands.
5+
6+
**Be sure to run `pip install -r requirements.txt` to install all the required packages.**
7+
8+
9+
**You will need the following API keys and tokens:**
10+
- Discord Bot Token (as "TOKEN" in a .env)
11+
- Reddit API Client ID (as "CLIENT_ID" in a .env)
12+
- Reddit API Client Secret (as "SECRET" in a .env)
13+
- Rapid API key (as "RAPID_API_KEY")
14+
- Perspective API key (in **line12** of **main.py**. Read the Note below.)
15+
16+
17+
**Note on Getting the Perspective API key:** You will need the access to Perspective API by Google. You can ask for access here: https://forms.gle/Pdj5KitPgoYHV9do7 . They usually take 30-40 minutes analyzing your responses and granting you with the link to enable the API in your Google Console. Before going further, make sure you have a project created in Google Console. After creating a project and enabling the API, you will need to generate the API key from the projects credentials page. Add your API key in **line 12** of **main.py** for the API to work and remove the commented function call on **line 77** of **main.py**.
18+
19+
20+
**Note on Developing without the Perspective API:** If you want to develop the bot without getting the Perspective API, just leave **line 12** in **main.py** as it is and never remove the comment on **line 77** of **main.py**.

cogs/GitHub.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ async def gituser(self, ctx, username):
4545
await ctx.send(embed=embed)
4646

4747

48+
@commands.command()
49+
async def contributors(self, ctx):
50+
url = 'https://api.github.com/repos/soulless-404/chintubot/contributors'
51+
response = requests.get(url)
52+
data = json.loads(response.text)
53+
embed = discord.Embed(title='People who have contributed in making the Chintu Bot')
54+
for contributor in data:
55+
embed.add_field(name=str(contributor['login']) + ' (' + contributor['html_url'] + ')', value = str(contributor['contributions'])+ ' commits', inline=False)
56+
57+
embed.set_thumbnail(url='https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png')
58+
await ctx.send(embed=embed)
4859

4960
def setup(bot):
5061
bot.add_cog(GitHub(bot))
639 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

main.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
import discord
44
from discord.ext import commands, tasks
55
from dotenv import load_dotenv
6-
6+
import requests
7+
import json
78
# import praw
89

910
load_dotenv()
1011

12+
api_key = 'YOUR PERSPECTIVE API KEY HERE'
13+
url = ('https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze' +
14+
'?key=' + api_key)
15+
1116
bot = commands.Bot(command_prefix='$')
1217

1318

@@ -20,6 +25,31 @@ async def on_ready():
2025
status = cycle(['WhiteHatJr SEO', ' with wolf gupta', 'with Lana Rhoades'])
2126

2227

28+
def toxicity_checker():
29+
@bot.event
30+
async def on_message(message):
31+
data_dict = {
32+
'comment': {'text': message.content},
33+
'languages': ['en'],
34+
'requestedAttributes': {'TOXICITY': {}}
35+
}
36+
37+
response = requests.post(url=url, data=json.dumps(data_dict))
38+
response_dict = json.loads(response.content)
39+
results = json.dumps(response_dict, indent=2)
40+
json_results = json.loads(results)
41+
toxicity = json_results['attributeScores']['TOXICITY']['summaryScore']['value']
42+
if toxicity > 0.95:
43+
await message.channel.purge(limit=1)
44+
await message.author.send(f'{message.author.mention} watch your language.')
45+
46+
else:
47+
pass
48+
49+
await bot.process_commands(message)
50+
51+
52+
2353
@tasks.loop(seconds=300)
2454
async def change_status():
2555
await bot.change_presence(activity=discord.Game(next(status)))
@@ -44,4 +74,5 @@ async def on_command_error(ctx, error):
4474
if filename.endswith(".py"):
4575
bot.load_extension(f'cogs.{filename[:-3]}')
4676

77+
#toxicity_checker()
4778
bot.run(os.getenv("TOKEN"))

0 commit comments

Comments
 (0)