GithubHelp home page GithubHelp logo

flamingov2's Introduction

FlamingoV2

About

This is FlamingoV2. It is the successor to Flamingo. It is a Discord bot with no intrinsic value. It's purely for the memes.

Permissions

Flamingo has the ability to restrict access to commands for users. Permissions can be set by role or user directly.

Permissions are evaluated as follows:

  1. User permissions for the command + action
  2. User permissions for the command
  3. Role permissions for the command + action
  4. Role permissions for the command

A command is the archetype of action a user is trying to perform (e.g. pasta) and an action is the exact action (e.g. get).

The first permission rule found using the above order determines a user's permission to execute a given command. Steps 3 and 4 are evaluated for each role in descending guild position. If no rules are found, Flamingo returns the value of the permissive flag for the guild. The permissive flag is set to true when Flamingo joins a guild. A true value treats absent permissons records (as opposed to an explicit allow or deny record) as the equivalent of a present allow. A false value treats absent permissions records as the equivalent of a present deny. The auth command is excluded from this paradigm. Auth requires explicit permission to invoke. By default, only the server owner has this permission.

Commands

auth

Auth commands are used to set permissions.

set

Sets the value of a permission rule for a given command and user or role

Usage: ~auth set command=$command *action=$action ^user=@user ^role=@role ^roleName="roleName" permission=$bool

* - optional argument

^ - XOR

delete

Removes a permission rule for a given command and user or role

Usage: ~auth delete command=$command *action=$action ^user=@user ^role=@role ^roleName="roleName" permission=$bool

* - optional argument

^ - XOR

test

Tests a permission rule for a given command and user

Usage: ~auth test command=$command *action=$action user=@user

* - optional argument

permissive

Sets the value of the permissive flag

Usage: ~auth permissive permission=$bool

list

Lists the permissions rules for the guild

Usage: ~auth list

strike

Issues a strike to a given user.

Usage: ~strike @user

get

Retrieves the strike count of a given user.

Usage: ~strike get @user

pasta

get

Retrieves a copypasta by alias and posts it. Alias can by any alphanumeric string with no whitespace.

Usage: ~pasta get $alias

save

Saves a new a copypasta by alias. Alias can by any alphanumeric string with no whitespace.

Usage: ~pasta save $alias $copypasta_text

edit

Updates an existing copypasta by alias. The copypasta must exist and by authored by the caller for this to succeed.

Usage: ~pasta save $alias $updated_copypasta_text

list

Retrieves a list of all the copypastas saved in the server and DMs them to the caller.

Usage: ~pasta list

react

get

Retrieves a reaction image by alias and posts it. Alias can by any alphanumeric string with no whitespace.

Usage: ~react get $alias

save

Saves a new a reaction by alias. Reactions are images uploaded to Discord. They are thumbnailed and saved for later reacall. Alias can by any alphanumeric string with no whitespace. Can be used to overwrite an existing reaction.

Usage: ~react save $alias

delete

Deletes a reaction image and makes it unavailable for use. Alias can by any alphanumeric string with no whitespace.

Usage: ~react delete $alias

list

Retrieves a list of all the reaction images saved and DMs them to the caller.

Usage: ~react list

Deployment

Local

go get -d -v ./...
go install -v ./...
$GOPATH/bin/FlamingoV2 -local=true -t="DISCORD TOKEN" -ak="AWS ACCESS KEY" -sk="AWS SECRET KEY" -r="AWS Region (e.g. us-west-2)"

AWS Fargate

Follow the AWS CD tutorial and pass the environment variables DISCORD_TOKEN, AWS_ACCESS_KEY, AWS_SECRET_KEY, REGION to the appropriate values.

flamingov2's People

Contributors

njha7 avatar danlemmond avatar chris-perkins avatar

Stargazers

 avatar  avatar Dhruv Chawla avatar

Watchers

James Cloos avatar  avatar

flamingov2's Issues

no code

Expected Behavior

  • there should be code

Current Behavior

  • there's no code

Possible Solution

  • add code

Steps to Reproduce

  1. view repo
  2. there's no code

Context (Environment)

  • Prod

Detailed Description

  • I don't want to write one

Possible Implementation

  • javascript or swift idk

Metrics for Service Clients

Service clients log errors and return 500s to users on failed commands. Should emit metrics to track frequency and alarm.

Plz read this

1: H-hewwo is anybody thewe

2: cave slowly begins to fill with water

1: H-hewwo pwease somebody hewp me H-ewwo!!

2: you can feel the surface of the water barely lapping at you

1: Nononono hewwo!! Hewwo! Hewp me

2: God wwest youw soul

1: Hewwo! Ma'am why awe you doing this to me Hewwo!! Hewp me pwease

2:

1: M-mr obama is that you Hewwo! Pwease hewp me i seem to be in a wittle bit of twubble mr obama hewwo H-hewwo

2: <picture of Obama; zoomed in slightly>

1: @( โ—• x โ—• )@

1: Pwease Mr Obama Pwease save me i downt wanna die

1: H-hewwo mr obama awe you still thewe

2: <picture of Obama; zoomed in slightly more>

1: M-mr obama pwease im drowning H-hewwo im scawed

1: Ill do anything fow you mr obama pwease hewp

2: Anything?

1: Anything for you mr obama :3

2: Then perish

2:

1: D:

Stale branches

Please delete stale branches once they are merged to master

Large Docker image

You could utilize multi-stage builds to avoid using the Go Docker image as it's fairly large. You should be able to compile the Go binary on the Golang image and then copy it to an Alpine image for a smaller footprint.

Commits

Commit messages are not nearly descriptive enough. I want to know EXACTLY what you ate, did, and who you talked to that led to the changes in code

Command Parsing Pattern not Scalable

FlamingoV2/flamingo.go

Lines 107 to 166 in cddd603

case commandPrefix + "strike":
switch {
case strings.HasPrefix(m.Message.Content, commandPrefix+"strike get"):
if len(m.Mentions) > 0 {
go strikeService.GetStrikesForUser(m.GuildID, m.ChannelID, m.Mentions[0].ID)
} else {
session.ChannelMessageSend(m.ChannelID, "Please mention a someone!")
}
case strings.HasPrefix(m.Message.Content, commandPrefix+"strike clear"):
if len(m.Mentions) > 0 {
go strikeService.ClearStrikesForUser(m.GuildID, m.ChannelID, m.Mentions[0].ID)
} else {
session.ChannelMessageSend(m.ChannelID, "Please mention a someone!")
}
default:
if len(m.Mentions) > 0 {
go strikeService.StrikeUser(m.GuildID, m.ChannelID, m.Mentions[0].ID)
} else {
session.ChannelMessageSend(m.ChannelID, "Please mention a someone!")
}
}
case commandPrefix + "pasta":
switch {
case strings.HasPrefix(m.Message.Content, commandPrefix+"pasta get"):
alias := strings.Replace(
strings.SplitAfterN(
m.Message.Content,
commandPrefix+"pasta get",
2)[1],
" ", "", -1)
if alias != "" {
go pastaService.GetPasta(m.GuildID, m.ChannelID, alias)
} else {
session.ChannelMessageSend(m.ChannelID, "Please specify a copypasta!")
}
case strings.HasPrefix(m.Message.Content, commandPrefix+"pasta save"):
aliasAndPasta := strings.SplitAfterN(
m.Message.Content,
commandPrefix+"pasta save",
2)[1]
aliasAndPasta = strings.TrimSpace(aliasAndPasta)
var aliasBuilder strings.Builder
for _, v := range aliasAndPasta {
if v == '\u0020' {
break
}
aliasBuilder.WriteRune(v)
}
alias := aliasBuilder.String()
pasta := strings.SplitAfterN(
aliasAndPasta,
alias,
2)[1]
if alias == "" || pasta == "" {
session.ChannelMessageSend(m.ChannelID, "Please specify an alias or copypasta!")
return
}
go pastaService.SavePasta(m.GuildID, m.ChannelID, m.Author.ID, alias, pasta)
}
}

The lines of code in the linked snippet will not scale well if additional commands are added. If another feature were to be added, the linked function would easily span 100+ lines. I would suggest the following design strategy:

Strategy 1

  • Have each Command Service (Currently Strike, Pasta Service) inherit from an interface CommandService.
    • CommandService should implement the following methods:
      • canHandleRequest(request []string) - Used to determine if a Command Service can run the command. For example, the pasta service CAN run ["pasta", "get", "top_prestige"] but it cannot run ["strike", "tdorno"].
      • executeRequest(request []string) - Used to execute the request. For example, ["pasta", "list"] will execute the pasta list command on the Pasta Service.

The strategy for running:

  1. Keep a list of Command Services that are running in a list []CommandService
  2. For every input command, split it into a list of strings by splitting on new line characters and spaces. In this example, let's call the resulting []string requestParameters
  3. For each command service in the list described in (1), check commandService.canHandleRequest(requestParameters)
  4. If the above check is successful, run commandService.executeRequest(requestParameters)

This methodology allows for multiple services to be able to execute on one command while keeping holding up SOLID design principles. Single Responsibility OP.

Alternative Strategy

  • Keep a map from String -> Void Lambda Function in memory
    • This Lambda function should map to the appropriate Command Service function.

Why this isn't the main strategy

Lambda functions would be annoying to deal with in golang if they do not conform to a common interface. For example, some commands might need string parameters, while others might not. However, if you believe the Command Services this system provides in the future will always be of type name(args []string), this strategy is fast in execution due to map get calls being O(1) asymptotically.

I might still suggest putting such behavior in a separate class (CommandHandler?) to uphold SOLID principles.

Keep up the scalable work!

Use packages to better organize components

Right now, all the code is housed in the main package. While this is mainly due to Go's shitty workspace limitation, I think we can improve upon this while reducing overall clutter. I suggest that you create contextual subfolders (services, commands, resources, etc.), as independent packages, to promote a better separation of concerns. This repository will not scale to 200+ developers if everything lives in the main package.

Very important problem

You're using tabs instead of spaces, so when I open it up in my editor where tabs are 8 spaces wide, it looks awful

Missing Docker Compose

I'd like the peace of mind that the bot has sufficient redundancy to support crashes and outages. A docker swarm or docker compose YAML would be great.

Random pasta of the day

Add the functionality to randomize the selection of a pasta and post it on a daily basis.

The bot optionally should allow admins to specify a custom channel for output.

Yikes

(see issue title)

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.