Browse Source

v0.0.1

master
Jonathan de Jong 3 years ago
commit
f79bf1a2a2
  1. 38
      .drone.yml
  2. 356
      .gitignore
  3. 81
      cogs/alias/__init__.py
  4. 22
      setup.py

38
.drone.yml

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
---
kind: pipeline
name: PyPi Publish
type: docker
steps:
- name: Publish JBOI PyPi
image: plugins/pypi
failure: ignore
settings:
username:
from_secret: jboi_username
password:
from_secret: jboi_password
repository: https://pypi.jboi.dev
distributions:
- sdist
- bdist_wheel
- name: Publish Public PyPi
image: plugins/pypi
failure: ignore
settings:
username:
from_secret: pypi_username
password:
from_secret: pypi_password
distributions:
- sdist
- bdist_wheel
when:
event:
- tag
ref:
- refs/tags/v*
repo:
- ShadowJonathan/SNEK-Alias

356
.gitignore vendored

@ -0,0 +1,356 @@ @@ -0,0 +1,356 @@
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
# Created by https://www.gitignore.io/api/windows,visualstudiocode,intellij,intellij+all,intellij+iml,python,venv
# Edit at https://www.gitignore.io/?templates=windows,visualstudiocode,intellij,intellij+all,intellij+iml,python,venv
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
.idea/**/sonarlint/
# SonarQube Plugin
.idea/**/sonarIssues.xml
# Markdown Navigator plugin
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator/
### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
# Generated files
# Sensitive or high-churn files
# Gradle
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
# Mongo Explorer plugin
# File-based project format
# IntelliJ
# mpeltonen/sbt-idea plugin
# JIRA plugin
# Cursive Clojure plugin
# Crashlytics plugin (for Android Studio and IntelliJ)
# Editor-based Rest Client
# Android studio 3.1+ serialized cache file
### Intellij+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
.idea/
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
*.iml
modules.xml
.idea/misc.xml
*.ipr
# Sonarlint plugin
.idea/sonarlint
### Intellij+iml ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
# Generated files
# Sensitive or high-churn files
# Gradle
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
# Mongo Explorer plugin
# File-based project format
# IntelliJ
# mpeltonen/sbt-idea plugin
# JIRA plugin
# Cursive Clojure plugin
# Crashlytics plugin (for Android Studio and IntelliJ)
# Editor-based Rest Client
# Android studio 3.1+ serialized cache file
### Intellij+iml Patch ###
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
### venv ###
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
pyvenv.cfg
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
pip-selfcheck.json
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# End of https://www.gitignore.io/api/windows,visualstudiocode,intellij,intellij+all,intellij+iml,python,venv
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)

81
cogs/alias/__init__.py

@ -0,0 +1,81 @@ @@ -0,0 +1,81 @@
import re
from discord.ext.commands import group, command
from pony.orm import Database, db_session, Required, PrimaryKey, commit
from snek import SNEK, UsesDatabase, IAlias, SNEKContext
class AliasCog(IAlias, UsesDatabase):
async def do_db(self, db: Database) -> None:
class Alias(db.Entity):
key = PrimaryKey(str)
val = Required(str)
self.Alias = Alias
def __init__(self, bot):
self.bot = bot # type: SNEK
def get(self, name):
for k, v in self.get_all().items():
if re.match(f"^{k}$", name):
return v
@db_session
def get_all(self):
j = dict()
for p in self.Alias.select():
j[p.key] = p.val
return j
@group()
@SNEK.is_mod()
async def alias(self, ctx: SNEKContext):
"""Set global aliases."""
if ctx.invoked_subcommand is None:
await ctx.send_help("alias")
@alias.command(name="get")
async def alias_get(self, ctx: SNEKContext, name: str):
"""Gets an alias from the database."""
v = self.get(name)
if v:
await ctx.send(f"Alias {name!r}:\n {v!r}")
else:
await ctx.send(f"Alias {name!r} does not exist.")
@alias.command(name="set")
async def alias_set(self, ctx: SNEKContext, name: str, *,
val: str):
"""Sets an alias."""
with db_session:
if not self.Alias.exists(key=name):
self.Alias(key=name, val=val)
else:
self.Alias[name].set(val=val)
await ctx.send("Set alias.")
@alias.command(name="del")
async def alias_del(self, ctx: SNEKContext, name: str):
"""Deletes an alias from the database."""
with db_session:
if self.Alias.exists(key=name):
a = self.Alias[name]
a_val = a.val
a.delete()
commit()
await ctx.send("Deleted alias.")
await self.bot.log(f"Alias {name!r} deleted, it contained {a_val!r}", _for="ALIAS")
else:
await ctx.send("Alias doesn't exist.")
@command()
async def aliases(self, ctx: SNEKContext):
"""List all known aliased commands."""
await ctx.send(f"`Alias commands:`\n```py\n{self.get_formatted()}\n```",
no_code=True)
def setup(bot: SNEK):
bot.add_cog(AliasCog(bot))

22
setup.py

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
import setuptools
setuptools.setup(
name="d-snek-cogs-alias",
version="0.0.1",
author="Jonathan de Jong",
author_email="jonathan@automatia.nl",
description="Discord SNEK Cog; Alias",
url="https://git.jboi.dev/ShadowJonathan/snek-alias",
packages=['cogs.alias'],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires=">=3.6",
install_requires=["d-snek>=1.2.4", "discord.py>=1.2.5"],
setup_requires=["wheel"],
extras_require={
"dev": ["ipython", "twine"],
}
)
Loading…
Cancel
Save