-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin: add random image plugin. (#154)
* Added random image plugin. * reformatted with black. * ran black formatter on info.
- Loading branch information
1 parent
bc1e27c
commit 336add6
Showing
5 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
NAME = "random_image.py" | ||
ORIGINAL_AUTHORS = ["Rakesh Seal"] | ||
|
||
ABOUT = """ | ||
Returns a random image url. | ||
""" | ||
|
||
COMMANDS = """ | ||
>>> .random_image | ||
returns a random image url. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
[random_image.py] | ||
Random Image Plugin | ||
[Author] | ||
Rakesh Seal | ||
[About] | ||
Returns a random image url. | ||
[Website] | ||
[Commands] | ||
>>> .random_image | ||
returns a random image url. | ||
""" | ||
|
||
import requests | ||
|
||
|
||
class Plugin: | ||
def __init__(self): | ||
self.url = "https://random.imagecdn.app/v1/image?width=500&height=150&category=buildings&format=json" | ||
|
||
def run(self, incoming, methods, info, bot_info): | ||
try: | ||
msgs = info["args"][1:][0].split() | ||
if info["command"] == "PRIVMSG" and msgs[0] == ".random_image": | ||
image_url = requests.get(self.url).json()["url"] | ||
methods["send"](info["address"], image_url) | ||
except Exception as e: | ||
print("blank!", e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requests |