Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #46 from Charibdys/v0.7
Browse files Browse the repository at this point in the history
V0.7 - Implement configurable ranks and command permissions
  • Loading branch information
Charibdys committed May 10, 2023
2 parents bf4b4a4 + fe6e094 commit 0cc3047
Show file tree
Hide file tree
Showing 12 changed files with 737 additions and 285 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ The following features are planned and being worked on:
- [X] Downvotes
- [x] Message queue
- [x] Spam prevention
- [ ] Configuration
- [ ] Configurable roles and command permissions
- [X] Configuration
- [X] Configurable roles and command permissions
- [X] Configurable cache contents/data
- [x] Configurable cache life
- [x] Configurable time and content limits for spam filter
Expand Down
42 changes: 37 additions & 5 deletions config.yaml.copy
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ locale: "en-US"
#log_file: "./log.txt"

# Modify lifetime of a message, in hours (24 hours is the default)
# This should be between 1 and 48 hours (inclusive)
# Can be set greater than or equal to 1
# NOTE: Increasing this value will increase RAM usage if database history is not enabled
#lifetime: 24

# Limit usage of /sign and /tsign for once every interval (seconds)
Expand All @@ -23,13 +24,45 @@ locale: "en-US"
#upvote_limit_interval: 0
#downvote_limit_interval: 0

# Toggle whether or not users can see the full count of joined, left, and blacklisted users.
#full_usercount: false
# Contact link or username shown to blacklisted users
#blacklist_contact: "t.me/pointofcontact_"

# Persist message history
# Use the database in place of the message cache; message history remains if bot restarts
#database_history: true

# Allow users to send photos, videos, or GIFs with a spoiler overlay
#allow_media_spoilers: true

# A list of ranks recognized by the bot
# To add a rank, add a new entry and define the name, value, and permissisons
#
# The following permissions are available:
# users upvote downvote promote promote_lower promote_same demote sign tsign ranksay
# ranksay_lower warn delete uncooldown remove purge blacklist motd_set ranked_info
ranks:
- name: "Banned"
value: -10
permissions: []
- name: "User"
value: 0
permissions: ["upvote", "downvote", "sign", "tsign"]
- name: "Mod"
value: 10
permissions: ["upvote", "downvote", "sign", "tsign",
"ranked_info", "users", "warn", "delete", "ranksay"]
- name: "Admin"
value: 100
permissions: ["upvote", "downvote", "sign", "tsign",
"ranked_info", "users", "warn", "delete", "uncooldown",
"remove", "purge", "blacklist", "ranksay"]
- name: "Host"
value: 1000
permissions: ["upvote", "downvote", "sign", "tsign",
"ranked_info", "users", "promote_lower", "demote",
"warn", "delete", "uncooldown", "remove", "purge",
"blacklist", "motd_set", "ranksay_lower"]

# Command toggles
# First value toggles the command (true to enable, false to disable)
# Second value, if true, will register the command with BotFather
Expand All @@ -48,8 +81,7 @@ enable_motd: [true, true]
enable_help: [true, true]
enable_upvotes: [true, false]
enable_downvotes: [true, false]
enable_mod: [true, false]
enable_admin: [true, false]
enable_promote: [true, false]
enable_demote: [true, false]
enable_warn: [true, false]
enable_delete: [true, false]
Expand Down
42 changes: 31 additions & 11 deletions locales/en-GB.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,26 @@ replies:
- |-
_There was no user found with that OID\._
# no_rank_found: ranks
- |-
_There was no rank found with that name\. Ranks are: [#{ranks}]_
# promoted: rank
- |-
_You have been promoted to #{rank}\! Type /help to view the commands available to you\._
# help_header
- |-
__*General Commands*__
# help_rank_commands: rank
- |-
__*Commands available to #{rank}*__
# help_reply_commands
- |-
__*Commands that require a reply*__
# toggle_karma: toggle
- |-
*Karma notifications*: #{toggle}
Expand Down Expand Up @@ -223,7 +239,12 @@ replies:
# blacklisted: reason
- |-
_You have been blacklisted#{reason}_
_You have been blacklisted#{reason}
#{contact}_
# blacklist_contact: contact
- |-
Contact: #{contact}
# purge_complete: msgs_deleted
- |-
Expand All @@ -233,6 +254,9 @@ replies:
- |-
# fail
- |-
# Special characters in MarkdownV2 must be escaped
command_descriptions:
Expand Down Expand Up @@ -276,17 +300,13 @@ command_descriptions:
- |-
Set or view your tripcode
# mod
- |-
Promote a user to the moderator rank
# admin
# promote
- |-
Promote a user to the administrator rank
Promote a user to a given rank
# demote
- |-
Demote a ranked user to the user rank
Demote a user to a given rank
# sign
- |-
Expand All @@ -298,7 +318,7 @@ command_descriptions:
# ranksay
- |-
Sign a message with your current rank (Alias of modsay/adminsay)
Sign a message with your current rank
# warn
- |-
Expand Down Expand Up @@ -363,9 +383,9 @@ logs:
- |-
User #{id}, aka #{name}, has been promoted to #{rank} by #{invoker}.
# demoted: id, name, invoker
# demoted: id, name, rank, invoker
- |-
User #{id}, aka #{name}, has been demoted by #{invoker}.
User #{id}, aka #{name}, has been demoted to #{rank} by #{invoker}.
# warned: id, name, oid, duration, reason
- |-
Expand Down
42 changes: 31 additions & 11 deletions locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,26 @@ replies:
- |-
_There was no user found with that OID\._
# no_rank_found: ranks
- |-
_There was no rank found with that name\. Ranks are: [#{ranks}]_
# promoted: rank
- |-
_You have been promoted to #{rank}\! Type /help to view the commands available to you\._
# help_header
- |-
__*General Commands*__
# help_rank_commands: rank
- |-
__*Commands available to #{rank}*__
# help_reply_commands
- |-
__*Commands that require a reply*__
# toggle_karma: toggle
- |-
*Karma notifications*: #{toggle}
Expand Down Expand Up @@ -223,7 +239,12 @@ replies:
# blacklisted: reason
- |-
_You have been blacklisted#{reason}_
_You have been blacklisted#{reason}
#{contact}_
# blacklist_contact: contact
- |-
Contact: #{contact}
# purge_complete: msgs_deleted
- |-
Expand All @@ -233,6 +254,9 @@ replies:
- |-
# fail
- |-
# Special characters in MarkdownV2 must be escaped
command_descriptions:
Expand Down Expand Up @@ -276,17 +300,13 @@ command_descriptions:
- |-
Set or view your tripcode
# mod
- |-
Promote a user to the moderator rank
# admin
# promote
- |-
Promote a user to the administrator rank
Promote a user to a given rank
# demote
- |-
Demote a ranked user to the user rank
Demote a user to a given rank
# sign
- |-
Expand All @@ -298,7 +318,7 @@ command_descriptions:
# ranksay
- |-
Sign a message with your current rank (Alias of modsay/adminsay)
Sign a message with your current rank
# warn
- |-
Expand Down Expand Up @@ -363,9 +383,9 @@ logs:
- |-
User #{id}, aka #{name}, has been promoted to #{rank} by #{invoker}.
# demoted: id, name, invoker
# demoted: id, name, rank, invoker
- |-
User #{id}, aka #{name}, has been demoted by #{invoker}.
User #{id}, aka #{name}, has been demoted to #{rank} by #{invoker}.
# warned: id, name, oid, duration, reason
- |-
Expand Down
4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: privateparlor
version: 0.6.5
version: 0.7

dependencies:
tourmaline:
Expand All @@ -18,4 +18,4 @@ targets:
privateparlor:
main: src/privateparlor.cr

crystal: 1.7.3
crystal: 1.8.1
20 changes: 18 additions & 2 deletions src/privateparlor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,37 @@ require "tasker"
require "sqlite3"
require "./privateparlor/*"

VERSION = "0.6.6"
VERSION = "0.7"

bot = PrivateParlor.new(Configuration.parse_config)

Log.info { bot.replies.substitute_log(:start, {"version" => VERSION}) }

Signal::INT.trap do
bot.stop_polling
end

Signal::TERM.trap do
bot.stop_polling
end

# Start message sending routine
spawn(name: "SendingQueue") do
spawn(name: "private_parlor_loop") do
loop do
if msg = bot.queue.shift?
bot.send_messages(msg)
else
break unless bot.polling
Fiber.yield
end
end

# Bot stopped polling from SIGINT/SIGTERM, shut down
bot.database.db.close
Log.info { "Sent last messages in queue. Shutting down..." }
exit
end

bot.poll

sleep
Loading

0 comments on commit 0cc3047

Please sign in to comment.