Skip to content

Commit

Permalink
Merge branch 'cloud-discordshim' into 'dev'
Browse files Browse the repository at this point in the history
Cloud discordshim

See merge request cameron/OctoPrint-DiscordRemote!6
  • Loading branch information
cameroncros committed Jun 29, 2023
2 parents 938c1c2 + a4643ca commit 1180def
Show file tree
Hide file tree
Showing 40 changed files with 1,219 additions and 1,623 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[bumpversion]
current_version = 4.7.0
current_version = 5.0.0

[bumpversion:file:setup.py]
35 changes: 25 additions & 10 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
stages: # List of stages for jobs, and their order of execution
- python36
- python37
- python38
- python39
- python310
- full_test

.test-job:
needs: []
timeout: 5m
timeout: 10m
retry: 2
script:
- |
Expand All @@ -18,13 +17,7 @@ stages: # List of stages for jobs, and their order of execution
- pip install -r requirements.txt -r requirements-dev.txt OctoPrint==$OCTOVER
- python setup.py bdist_wheel
- pip install dist/*.whl
- pytest --cov --cov-report term --cov-report xml:coverage.xml
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
- FAST_TEST=1 pytest

python38:
stage: python38
Expand All @@ -49,3 +42,25 @@ python310:
- OCTOVER: [ '1.7.3', '1.8.7', '1.9.0rc5' ]
extends: .test-job
image: python:3.10

full_test:
stage: python310
image: python:3.10
timeout: 20m
retry: 2
script:
- |
cat <<EOT >> config.yaml
channelid: '$CHANNEL_ID'
bottoken: '$BOT_TOKEN'
EOT
- pip install -r requirements.txt -r requirements-dev.txt OctoPrint=='1.8.7'
- python setup.py bdist_wheel
- pip install dist/*.whl
- pytest --cov --cov-report term --cov-report xml:coverage.xml
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
24 changes: 24 additions & 0 deletions .run/discordshim.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="discordshim" type="PythonConfigurationType" factoryName="Python">
<module name="OctoPrint-DiscordRemote" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="CONFIG" value="config.yaml" />
</envs>
<option name="SDK_HOME" value="$PROJECT_DIR$/testenv/bin/python" />
<option name="SDK_NAME" value="Python 3.11 (OctoPrint-DiscordRemote)" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="octoprint_discordshim" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="true" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>
29 changes: 12 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# OctoPrint-DiscordRemote

DiscordRemote is a plugin allowing Octoprint to send notifications to a Discord channel.
The plugin acts as a Discord bot, which allows it to listen on the channel and respond to commands to control the printer.
There is a small amount of configuration needed on Discord to create the bot, but no programming is required.
The plugin connects to a [DiscordShim](https://github.com/cameroncros/discordshim_rs)
which manages the actual discord interactions.

There is an existing DiscordShim that is already setup, or users may create and use their own DiscordShim instance.

This is forked from https://github.com/bchanudet/OctoPrint-Octorant.

Note, using this plug-in requires building and setting up your own discord bot.
Note, using this plug-in requires either:

[![](https://circleci.com/gh/cameroncros/OctoPrint-DiscordRemote.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/cameroncros/OctoPrint-DiscordRemote)
- Adding the existing discordshim bot to your server:
- https://discord.com/oauth2/authorize?client_id=433252064324354048&permissions=11264&scope=bot
or
- Self host your own discordshim:
- https://github.com/cameroncros/discordshim_rs

License : MIT

Expand Down Expand Up @@ -52,21 +59,10 @@ or manually using this URL:

https://github.com/cameroncros/OctoPrint-DiscordRemote/archive/master.zip

### Create the Discord Bot in Discord

See the following link for instructions on how to setup a Discord bot:

https://github.com/Chikachi/DiscordIntegration/wiki/How-to-get-a-token-and-channel-ID-for-Discord


#### Tips

- The Channel ID is the ID of the TEXT channel within the Discord Server that the bot is communicating with, not the Discord Server.
- When following (https://github.com/Chikachi/DiscordIntegration/wiki/How-to-get-a-token-and-channel-ID-for-Discord), STOP after "Get the channel ID of the Discord text channel" section. Everything else is not needed on that page.
- You **must** enable all "Privileged Intents" as shown in the screenshot below
![image](https://github.com/Coder-Tavi/OctoPrint-DiscordRemote/assets/66774833/f12ac7b1-2423-4062-a5cf-435bb3599ed9)
- OAuth2 permissions are not necessary.
- If you reinstall your Octoprint system, you only need the bot token and channel ID to get it back up and running.
- If you reinstall your Octoprint system, you only need the channel ID, and DiscordShim address to get it back up and running.

## API

Expand Down Expand Up @@ -114,7 +110,6 @@ The plugin can be configured in the configuration panel, under the "DiscordRemot

### Discord Settings

- Bot Token: The token for a discord bot.
- Channel ID: The ID of a channel the bot will listen and post to.
Ensure that this is locked down so that strangers cannot send commands to your printer, or whitelist users using the "Access Settings"

Expand Down
81 changes: 81 additions & 0 deletions bot_tester.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# This example requires the 'members' and 'message_content' privileged intents to function.

import discord
import yaml
from discord.ext import commands
import random

description = '''An example bot to showcase the discord.ext.commands extension
module.
There are a number of utility commands being showcased here.'''

intents = discord.Intents.default()
intents.members = True
intents.message_content = True

bot = commands.Bot(command_prefix='?', description=description, intents=intents)


@bot.event
async def on_ready():
print(f'Logged in as {bot.user} (ID: {bot.user.id})')
print('------')


@bot.command()
async def add(ctx, left: int, right: int):
"""Adds two numbers together."""
await ctx.send(left + right)


@bot.command()
async def roll(ctx, dice: str):
"""Rolls a dice in NdN format."""
try:
rolls, limit = map(int, dice.split('d'))
except Exception:
await ctx.send('Format has to be in NdN!')
return

result = ', '.join(str(random.randint(1, limit)) for r in range(rolls))
await ctx.send(result)


@bot.command(description='For when you wanna settle the score some other way')
async def choose(ctx, *choices: str):
"""Chooses between multiple choices."""
await ctx.send(random.choice(choices))


@bot.command()
async def repeat(ctx, times: int, content='repeating...'):
"""Repeats a message multiple times."""
for i in range(times):
await ctx.send(content)


@bot.command()
async def joined(ctx, member: discord.Member):
"""Says when a member joined."""
await ctx.send(f'{member.name} joined {discord.utils.format_dt(member.joined_at)}')


@bot.group()
async def cool(ctx):
"""Says if a user is cool.
In reality this just checks if a subcommand is being invoked.
"""
if ctx.invoked_subcommand is None:
await ctx.send(f'No, {ctx.subcommand_passed} is not cool')


@cool.command(name='bot')
async def _bot(ctx):
"""Is the bot cool?"""
await ctx.send('Yes, the bot is cool.')

if __name__ == '__main__':
with open('config.yaml') as f:
data = yaml.load(f)

bot.run(data['bottoken'])
2 changes: 0 additions & 2 deletions config.yaml.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
channelid: "DO NOT COMMIT CHANGES TO THIS FILE"
bottoken: "DO NOT COMMIT CHANGES TO THIS FILE"

14 changes: 10 additions & 4 deletions configtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
bot_details = {}
try:
with open(config_file, "r") as config:
bot_details = yaml.load(config.read(), Loader=yaml.SafeLoader)
bot_details = yaml.load(config.read(), Loader=yaml.SafeLoader)
except:
print("To test discord bot posting, you need to create a file "
"called config.yaml in the root directory with your bot "
"details. NEVER COMMIT THIS FILE.")
"called config.yaml in the root directory with your bot "
"details. NEVER COMMIT THIS FILE.")
exit()

octo_config = {}
Expand All @@ -22,6 +22,12 @@

octo_config['plugins']['discordremote'] = bot_details

# Prevent save mode
octo_config['server']['ignoreIncompleteStartup'] = True

# Disable login
octo_config['accessControl']['autologinLocal'] = True
octo_config['accessControl']['autologinAs'] = 'admin'

with open(octoprint_config, "w") as config:
yaml.safe_dump(octo_config, stream=config, default_flow_style=False, indent=2, allow_unicode=True)

Loading

0 comments on commit 1180def

Please sign in to comment.