Giter Site home page Giter Site logo

dgnsrekt / discorgeous Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 2.0 207 KB

Discord + GTTS = a discord bot that sends google text to speech voice messages to discord voice channels.

License: MIT License

Python 100.00%
discord bot gtts google-text-to-speech python python3 discord-bot music-bot discord-server discord-py discord-py-bot discord-python-bot speech tts text-to-speech

discorgeous's Introduction

Discorgeous

Discord + GTTS = a discord bot that sends google text to speech voice messages to discord voice channels.

Code style: black

    ____   _
   / __ \ (_)_____ _____ ____   _____ ____ _ ___   ____   __  __ _____
  / / / // // ___// ___// __ \ / ___// __ `// _ \ / __ \ / / / // ___/
 / /_/ // /(__  )/ /__ / /_/ // /   / /_/ //  __// /_/ // /_/ /(__  )
/_____//_//____/ \___/ \____//_/    \__, / \___/ \____/ \__,_//____/
                                   /____/

Usage: discorgeous [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  client      Send a single message to server.
  client-ssh  ssh client not implemented.
  repl        Repl messages to server.
  server      Runs the discord bot server.
  tester      Sends test song to server.

REQUIRES

On Linux environments, installing discord.py[voice] requires getting the following dependencies:

apt install libffi-dev libnacl-dev

QUICK START

Install

git clone https://github.com/dgnsrekt/Discorgeous.git
cd Discorgeous
pip3 install -e .

Run Single Server

discorgeous server --single --port 5555 --token {discord_bot_token} --channel {discord_channel_id}

Run REPL Client

discorgeous repl --port 5555

Run Test Song

discorgeous tester --port 5555

Run Muliple Servers

First edit the server_config.toml file in the Discorgeous/config folder. Add as many servers as you like.

[ServerOne] <- Whatever name you want.
CHANNEL_ID = "000000000000000000" <- {discord_channel_id}
VOICE_TOKEN = "00000000000000000000000000000000000000000000000000000000000" <- {discord_bot_token}
IP = "0.0.0.0"
PORT = "6666" <- Make sure each server has a different port.

[ServerTwo] <- Whatever name you want.
CHANNEL_ID = "111111111111111111" <- {discord_channel_id}
VOICE_TOKEN = "11111111111111111111111111111111111111111111111111111111111" <- {discord_bot_token}
IP = "0.0.0.0"
PORT = "5555" <- Make sure each server has a different port.

Run server with configuration section name

discorgeous server --config ServerOne --config ServerTwo

Run in seperate tmux instances

discorgeous server --config ServerOne --config ServerTwo --tmux

Example Client Script

The MinuteNotificationClient sends a current time message to a discorgeous server every minute.

from discorgeous import Client
from datetime import datetime
import asyncio
import sys


class MinuteNotificationClient(Client):
    def __init__(self, *, ip, port, sleep_interval=60):
        super().__init__(ip=ip, port=port)
        self.sleep_interval = sleep_interval

    async def timeupdate(self, *, loop):
        while True:
            current_time = datetime.now().time()
            hour = current_time.hour
            minute = current_time.minute
            message = f"The current time is {hour} {minute}."
            await self.handler(message, loop)
            await asyncio.sleep(self.sleep_interval)

    def start(self):
        loop = asyncio.get_event_loop()
        time_coro = self.timeupdate(loop=loop)
        loop.run_until_complete(time_coro)

        try:
            loop.run_forever()
        except KeyboardInterrupt as e:
            print(e)
        finally:
            loop.close()


MNC = MinuteNotificationClient(ip="localhost", port=6666, sleep_interval=60)

try:
    MNC.start()
except KeyboardInterrupt as e:
    print(str(e))
except Exception as e:
    print(str(e))
finally:
    sys.exit()

TODO

  • Client over SSH
  • Documentation
  • Tests
  • Config files in user path.
  • Update Requirements.
  • Link to discord voice bot token creation guide.
  • Add port/name check to server config to make sure all ports and names are unique.
  • Add non-async version of the client.
  • Dump Client config.
  • Example Random lyrics/quotes.
  • client.start() method should take a list of coroutines, add them to a loop, then start.
  • Py package
  • Update for discord.py 1.0

Contact

License

This code is licensed under the MIT License.

discorgeous's People

Contributors

dgnsrekt avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

xtansia selus

discorgeous's Issues

Need to catch.

Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/gtts/tts.py", line 218, in write_to_fp
r.raise_for_status()
File "/usr/local/lib/python3.6/dist-packages/requests/models.py", line 939, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://translate.google.com/translate_tts?ie=UTF-8&q=DTA%2FBTC%2C+fdbi+breakout%2C+four+hour+GREEN++candle%2C+inside+cloud%2C+true_risk.&tl=en-au&ttsspeed=1&total=1&idx=0&client=tw-ob&textlen=73&tk=389205.226589

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/root/Discorgeous/discorgeous/main.py", line 12, in
main()
File "/root/Discorgeous/discorgeous/main.py", line 8, in main
cli()
File "/usr/lib/python3/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/lib/python3/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/lib/python3/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/lib/python3/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/root/Discorgeous/discorgeous/cli.py", line 136, in server
server.run()
File "/root/Discorgeous/discorgeous/server.py", line 103, in run
self.loop.run_until_complete(asyncio.gather(client_bot_coro, server_coro, gtts_coro))
File "/usr/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete
return future.result()
File "/root/Discorgeous/discorgeous/server.py", line 42, in fetch_gtts_message
text_to_speech.write_to_fp(byte_stream)
File "/usr/local/lib/python3.6/dist-packages/gtts/tts.py", line 221, in write_to_fp
raise gTTSError(tts=self, response=r)
gtts.tts.gTTSError: 500 (Internal Server Error) from TTS API. Probable cause: Uptream API error. Try again later.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.