diff --git a/Scripting.md b/Scripting.md index 9addc9f..d8fe62a 100644 --- a/Scripting.md +++ b/Scripting.md @@ -20,6 +20,7 @@ As you can see the frequency at which this condition returns true depends on the ``` import obspython as obs import threading # Required by advss helpers +from typing import NamedTuple import random CONDITION_NAME = "Random condition" @@ -111,6 +112,7 @@ The action itself will allow you to configure the message to send and the channe ``` import obspython as obs import threading # Required by advss helpers +from typing import NamedTuple import discord from discord.ext import commands @@ -160,9 +162,9 @@ async def stop_bot(): def restart_bot(): - global token, bot_thread + global loop, token, bot_thread - if loop and bot.is_closed() == False: + if loop and not bot.is_closed(): asyncio.run_coroutine_threadsafe(stop_bot(), loop).result() bot_thread = threading.Thread(target=start_bot) @@ -236,7 +238,7 @@ def script_properties(): def script_load(settings): - global action_name + global action_name, bot_thread advss_register_action( action_name, run_action, @@ -248,7 +250,13 @@ def script_load(settings): def script_unload(): - global action_name + global action_name, loop, bot_thread + if loop: + if not bot.is_closed(): + asyncio.run_coroutine_threadsafe(stop_bot(), loop).result() + loop.call_soon_threadsafe(loop.stop) + bot_thread.join() + loop.close() advss_deregister_action(action_name) @@ -279,7 +287,7 @@ Note that this is only a very simple example which probably does not cover all e ``` import obspython as obs import threading # Required by advss helpers - +from typing import NamedTuple from pythonosc.dispatcher import Dispatcher from pythonosc import osc_server