Initial commit

This commit is contained in:
Layla 2020-09-13 05:26:44 +00:00
parent dd8ee450a2
commit 05f254a47e
6 changed files with 194 additions and 0 deletions

32
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,32 @@
name: Build & Publish
on:
release:
types:
- created
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Update Version
id: semver
uses: RightBrain-Networks/semver-action@1.0.0
with:
mode: get
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: build
run: |
python setup.py sdist bdist_wheel
- name: PyPi Publish
uses: pypa/gh-action-pypi-publish@v1.0.0a0
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}

28
.github/workflows/version.yml vendored Normal file
View File

@ -0,0 +1,28 @@
name: Version & Release
on:
push:
branches:
- master
jobs:
CheckVersion:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Run Auto-Semver
id: semver
uses: RightBrain-Networks/semver-action@1.0.0
- name: Create Release
id: create_release
uses: actions/create-release@v1
if: steps['semver']['outputs']['RETURN_STATUS'] == '0'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.semver.outputs.SEMVER_NEW_VERSION }}
release_name: ${{ steps.semver.outputs.SEMVER_NEW_VERSION }}
body: Release Version ${{ steps.semver.outputs.SEMVER_NEW_VERSION }}
draft: false
prerelease: false

5
.gitignore vendored
View File

@ -127,3 +127,8 @@ dmypy.json
# Pyre type checker # Pyre type checker
.pyre/ .pyre/
aws
.vscode/
awscliv2.zip
discord_config.ini

View File

@ -0,0 +1,58 @@
import discord, boto3, configparser, os, sys
version = "0.0.0"
# Get token at: https://discord.com/developers/applications/
config = configparser.ConfigParser()
config_path = "discord_config.ini"
if not os.path.exists(config_path):
with open(config_path, "w") as file_writer:
file_writer.write("""[discord]
token = {PUT TOKEN HERE}
ignore_user = {PUT USERNAME HERE}
[aws]
topic = {PUT TOPIC HERE}
profile = default""".replace(" ",""))
print(f"Please update '{config_path}'!")
sys.exit(0)
config.read(config_path)
session = boto3.session.Session(profile_name=config["aws"]["profile"])
bot_token = config["discord"]["token"]
sns = session.resource('sns').Topic(config["aws"]["topic"])
if sns == None:
print("SNS was configured poorly!")
sys.exit(0)
class Notifier(discord.Client):
async def on_ready(self):
print(f"Logged in as {self.user}")
guilds = ""
for guild in self.guilds:
guilds = guilds + ", " + str(guild)
print(f"Watching servers: {guilds[2:]}")
async def on_message(self, message):
if "do you see me?" in message.content.lower():
print(f"I see {message.author}")
await message.channel.send(":eye: You have been seen! :eye:")
if str(message.author) in [str(self.user), "The Genuine Wonder#2859"]:
return
# Format and print mesage
formatted_message = f"<{message.author}> \"{message.content}\" from #{message.channel} on {message.guild}"
print(formatted_message)
# Send notification to SNS
sns.publish(Message=formatted_message)
def main():
client = Notifier()
client.run(bot_token)
if __name__ == "__main__":
main()

5
requirements.txt Normal file
View File

@ -0,0 +1,5 @@
# requirements.txt
#
# installs dependencies from ./setup.py, and the package itself,
# in editable mode
-e .

66
setup.py Normal file
View File

@ -0,0 +1,66 @@
import re
from os import path
from setuptools import setup
from codecs import open
here = path.abspath(path.dirname(__file__))
# Get the long description from the README file
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
def read(*parts):
return open(path.join(here, *parts), 'r').read()
def find_version(*file_paths):
version_file = read(*file_paths)
version_match = re.search(r"^version = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")
setup(
name='discord-notifier',
version=find_version('discordnotifier','__init__.py'),
description='Simple discord notification bot',
long_description=long_description,
long_description_content_type="text/markdown",
# The project's main homepage.
url='https://github.com/josephbmanley/discord-notifier',
# Author details
author='Joseph Manley',
author_email='j@cloudsumu.com',
# Choose your license
license='MIT',
# See https://pypi.org/classifiers/
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8'
],
keywords='AWS,Discord,Cloud,Notification',
packages=["discordnotifier"],
install_requires=['boto3','discord.py'],
package_data={},
entry_points={
'console_scripts' : [
'discordnotifier = discordnotifier:main'
]
}
)