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

Commit e47f609

Browse files
committed
Move to Gs6Ex
1 parent 8ec6a04 commit e47f609

13 files changed

+126
-493
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
__pycache__
2-
config.json
32
.DS_Store
43
*.sublime-*

README.md

+2-40
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,3 @@
1-
# TCD Helper Bot
1+
# Helper
22

3-
A (not so) simple Discord bot that helps programmers find what they are looking for.
4-
5-
Written for the [TCD Discord server](https://discord.gg/code).
6-
7-
## Usage
8-
To use the bot, mention it with your command.
9-
10-
```@helper help```
11-
12-
In direct messages the mention is optional.
13-
14-
Use the `help` command to list available commands, or `_help` to list all commands, even hidden ones.
15-
16-
## Installation
17-
This bot requires Python 3.6+, as well as the [`requests`](https://pypi.org/project/requests/), [`discord.py`](https://pypi.org/project/discord.py/), and [`hjson`](https://pypi.org/project/hjson/) modules.
18-
```sh
19-
# Install dependencies
20-
$ python3 -m pip install -U requests
21-
$ python3 -m pip install -U discord.py[voice]
22-
$ python3 -m pip install -U hjson
23-
24-
# Clone repo
25-
$ git clone https://github.com/max-kamps/helper.git
26-
27-
# Create the config file
28-
$ cd helper
29-
$ cp example.config.hjson config.hjson
30-
31-
# Make sure to add your token to the config file
32-
33-
# Running
34-
$ cd ..
35-
$ python3 -m helper main
36-
```
37-
38-
## Running
39-
```sh
40-
$ python3 -m helper <account>
41-
```
3+
A [Gs6Ex](https://github.com/max-kamps/gs6ex) module set for the Coding Den Discord server.

__main__.py

-47
This file was deleted.

cheatsh.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import re
2+
from urllib.parse import quote_plus
3+
4+
import aiohttp
5+
6+
from ...common import *
7+
from ... import module as mod
8+
9+
10+
11+
escape_tt = str.maketrans({
12+
'`': '\\`'
13+
})
14+
15+
ansi_re = re.compile(r'\x1b\[.*?m')
16+
17+
18+
class CheatShModule(mod.Module):
19+
def on_load(self):
20+
self.conf.setdefault('max_length', 1000)
21+
self.conf.sync()
22+
23+
self.session = None
24+
25+
def on_unload(self):
26+
if self.session:
27+
self.log.info('Closing session...')
28+
mod.loop.create_task(self.session.close())
29+
30+
def result_fmt(self, url, language, body_text):
31+
body_space = min(1992 - len(language) - len(url), self.conf['max_length'])
32+
33+
if len(body_text) > body_space:
34+
return f'```{language}\n{body_text[:body_space - 20]}\n[...]```\nFull results: {url}'
35+
36+
return f'```{language}\n{body_text}```\n{url}'
37+
38+
@mod.command(name='csh', usage='csh <language> <search terms>', description='Search cheat.sh')
39+
async def cmd_csh(self, ctx, language: str, *search_terms: str):
40+
url = f'https://cheat.sh/{quote_plus(language)}/{quote_plus(" ".join(search_terms))}'
41+
42+
if not self.session:
43+
self.session = aiohttp.ClientSession()
44+
self.log.info('Session opened')
45+
46+
async with self.session.get(
47+
url,
48+
headers={'User-Agent': 'curl/7.68.0'},
49+
timeout=aiohttp.ClientTimeout(total=10)
50+
) as response:
51+
result = ansi_re.sub('', await response.text()).translate(escape_tt)
52+
53+
await ctx.send(self.result_fmt(url, language, result))

common.py

-38
This file was deleted.

example.config.hjson

-18
This file was deleted.

ext/cheatsh.py

-36
This file was deleted.

ext/extutil.py

-63
This file was deleted.

ext/help.py

-51
This file was deleted.

0 commit comments

Comments
 (0)