Code Monkey home page Code Monkey logo

discordpersonalassistant's Introduction

Discord Personal Assistant

A quick base for a Discord personal assistant using Discord Python API.

How it works

This Discord bot is build in a modular approach. It uses modules to allow you to define precisely what you want to do with your Discord Personal Assistant.

What is a module ?

A module is a part of your Discord Personal Assistant where you can define what it does. A module is built around two main concepts :

  1. Scrapping : A function called at a certain interval performing a specific action (Checking the news, parsing tweets, checking if your train is late, etc).
  2. Command : A function called by the user using a specific keyword, allowing you to handle interaction with users.

How to use

In order to run your discord assistant, you'll need to specify values in environment.py:

See

from modules import *

# Bot token
TOKEN = "your-bot-token"
# Mapping between channel's name and their IDs
# MUST contains a 'status' channel
CHANNELS = {
    "status" : 123456789123456789,
    "helloWorld" : 123456789213456789,
    "news" : 123456789123457689
}
# Every modules used by the bot
# Each module takes 2 parameters in its contructor :
# 1. A channel name (must match one of the channels set above) defining where the module is going to send its updates
# 2. A triggering interval defining de time (in seconds) between 2 scrapping actions  
ENABLED_MODULES = [
    # Exemple
    HelloWorldModule("news", 10)
]

You'll find every module in the modules folder.

How can I make my own modules ?

The whole idea of this project is to give you an easy way to build your own modules. To do so, you just have to define a new module in the modules directory following this structure :

from modules.module import Module

class HelloWorldModule(Module):
    """
    An exemple module, showing how it works
    """

    # Set a human friendly-name for your module
    name = "Hello world Module"
    # Define the string used to call this module command function
    commandTrigger = "hello"

    # Define actions that should be performed on module init
    async def init(self):
        return await super().init()

    # Define how your module is supposed tho handle commands
    async def command(self, args, channel):
        if args[0] == "hello":
            await channel.send("Hello!")
        return await super().command(args, channel)

    # Define your module scrapping behaviour
    async def scrap(self):
        await self.channel.send("Hello!")
        return await super().scrap()

    # Define your module behaviour when closing
    async def close(self):
        return await super().close()

Once your module is defined, you simply have to add it in the ENABLE_MODULES of your environment :

# Every modules used by the bot
# For each module takes 2 parameters in its contructor :
# 1. A channel name (must match one of the channels set above) defining where the module is going to send its updates
# 2. A triggering interval defining de time (in seconds) between 2 scrapping actions  
ENABLED_MODULES = [
    # Exemple
    HelloWorldModule("news", 10)
]

discordpersonalassistant's People

Watchers

 avatar

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.