def main(): from tornado.options import define, options define("port", default=8888, help="serve web requests from the given port", type=int) define("debug", default=False, help="run server in debug mode", type=bool) define("mktables", default=False, help="bootstrap a new sqlite database") define("migration", default='', help="run a named database migration") define("twitch", default=True, help="Connect to Twitch chat servers") define("twitchapi", default=True, help="Connect to Twitch API") define("discord", default=True, help="Connect to Discord chat servers") define("twitter", default=True, help="Connect to Twitter") define("newbot", default=False, help="Generates a Discord server invite link for a new bot instance") define("runtests", default=False, help="Run tests") tornado.options.parse_command_line() if options.mktables: from loggers.models import Message, Event from commands.models import Quote, Command from networks.models import User, Moderator from peewee import OperationalError for table in [Message, Event, Quote, Command, User, Moderator]: try: db.create_table(table) except OperationalError as e: # table (probably/hopefully) exists, dump this into the console warning(e) continue if options.migration: from db import Migrations if options.migration not in Migrations: error('No migration named "{}", ignoring.'.format(options.migration)) else: info('Attempting migration {}'.format(options.migration)) return Migrations[options.migration]() if options.runtests: tornado.testing.main() return app = App(app_debug=options.debug) http_server = tornado.httpserver.HTTPServer(app) tornado.platform.asyncio.AsyncIOMainLoop().install() # uses default asyncio.loop() http_server.listen(options.port) info('Serving on port %d' % options.port) # Discord options: ## new bot instance authentication if options.newbot: from keys import discord_app_id from discord_invite import invite_link print("Please go to the following link to authorize the bot, then press `Enter`:\n") print(invite_link(discord_app_id)) input("\nPress `Enter` to continue...") ## connect to discord if options.discord: from networks.deescord import Discord app.Discord = Discord() app.Discord.application = app tornado.ioloop.IOLoop.instance().add_callback(app.Discord.connect) # connect to Twitch API if options.twitchapi: from networks.twitch import TwitchParser, TwitchAPI app.TwitchAPI = TwitchAPI() app.TwitchAPI.application = app from tornado.httpclient import AsyncHTTPClient app.TwitchAPI.client = AsyncHTTPClient() tornado.ioloop.IOLoop.instance().add_callback(app.TwitchAPI.connect) # connect to Twitch chat if options.twitch: app.Twitch = TwitchParser() app.Twitch.application = app tornado.ioloop.IOLoop.instance().add_callback(app.Twitch.connect) if options.twitter: from networks.twatter import Twitter app.Twitter = Twitter(app) tornado.ioloop.IOLoop.instance().add_callback(app.Twitter.connect) # link the Jukebox to the application from commands.jukebox import J # our instance of the Jukebox app.Jukebox = J # on our instance of the Application tornado.ioloop.IOLoop.instance().start()
async def bot_invite(network, channel, message): link = invite_link(discord_app_id) await network.send_message(channel, 'Invite me to your server here: {}'.format(link))