Browse Source

Add initial files, currently running

master
Matthew Faltys 3 years ago
parent
commit
1df08f3115
  1. 53
      Makefile
  2. 9
      config.gcfg
  3. 19
      deps/Dockerfile
  4. 916
      deps/fortune/fortunes
  5. 1365
      deps/fortune/kenm
  6. 38122
      deps/fortune/showerthoughts
  7. 44
      deps/manifest.json
  8. 4
      deps/redis.conf
  9. BIN
      deps/rootfs.tar.gz
  10. 5
      deps/run.sh
  11. 8
      deps/run_lorebot.sh
  12. 14
      go.mod
  13. 20
      go.sum
  14. 111
      lorebot/botfunc.go
  15. 746
      lorebot/lorebot.go
  16. 72
      readme.md

53
Makefile

@ -0,0 +1,53 @@
GOC=go build
GOFLAGS=-a -ldflags '-s'
CGOR=CGO_ENABLED=0
IMAGE_NAME=lorebot
all: lorebot
depends:
go get github.com/unixvoid/glogger
go get gopkg.in/gcfg.v1
go get gopkg.in/redis.v5
go get github.com/bwmarrin/discordgo
lorebot:
$(GOC) lorebot/lorebot.go
run:
go run \
lorebot/lorebot.go \
lorebot/botfunc.go
stat:
mkdir -p bin/
$(CGOR) $(GOC) -o bin/lorebot $(GOFLAGS) lorebot/*.go
docker: stat
mkdir stage.tmp/
cp bin/lorebot stage.tmp/
cp deps/rootfs.tar.gz stage.tmp/
cp deps/Dockerfile stage.tmp/
cp deps/redis.conf stage.tmp/
chmod +x deps/run.sh
cp deps/run.sh stage.tmp/
cp -R deps/fortune stage.tmp/
cp config.gcfg stage.tmp/
cd stage.tmp/ && \
sudo docker build -t $(IMAGE_NAME) .
@echo "$(IMAGE_NAME) built"
test_docker:
mkdir -p /tmp/lorebot/redis/
touch /tmp/lorebot/dump.rdb
cp .auth /tmp/lorebot/
sudo docker run \
-it \
-v /tmp/lorebot/redis:/redisbackup:rw \
-v /tmp/lorebot/.auth:/.auth:ro \
$(IMAGE_NAME)
clean:
rm -rf bin/
rm -rf stage.tmp/
rm -rf lorebot.aci

9
config.gcfg

@ -0,0 +1,9 @@
[lorebot]
loglevel = "debug"
slackdebug = false
bootstrapdelay = 1
AuthFile = ".auth"
[redis]
host = "127.0.0.1:6379"
password = ""

19
deps/Dockerfile vendored

@ -0,0 +1,19 @@
FROM alpine
RUN apk --update add ca-certificates redis fortune
RUN mkdir /redisbackup/
RUN rm -rf /usr/share/fortune
COPY fortune/ /usr/share/fortune
WORKDIR /usr/share/fortune/
RUN strfile -c % fortunes fortunes.dat
RUN strfile -c % kenm kenm.dat
RUN strfile -c % showerthoughts showerthoughts.dat
#ADD rootfs.tar.gz /
COPY redis.conf /
COPY config.gcfg /
COPY lorebot /
COPY run.sh /
WORKDIR /
CMD ["/run.sh"]

916
deps/fortune/fortunes vendored

@ -0,0 +1,916 @@
A day for firm decisions!!!!! Or is it?
%
A few hours grace before the madness begins again.
%
A gift of a flower will soon be made to you.
%
A long-forgotten loved one will appear soon.
Buy the negatives at any price.
%
A tall, dark stranger will have more fun than you.
%
A visit to a fresh place will bring strange work.
%
A visit to a strange place will bring fresh work.
%
A vivid and creative mind characterizes you.
%
Abandon the search for Truth; settle for a good fantasy.
%
Accent on helpful side of your nature. Drain the moat.
%
Advancement in position.
%
After your lover has gone you will still have PEANUT BUTTER!
%
Afternoon very favorable for romance. Try a single person for a change.
%
Alimony and bribes will engage a large share of your wealth.
%
All the troubles you have will pass away very quickly.
%
Among the lucky, you are the chosen one.
%
An avocado-tone refrigerator would look good on your resume.
%
An exotic journey in downtown Newark is in your future.
%
Another good night not to sleep in a eucalyptus tree.
%
Are you a turtle?
%
Are you ever going to do the dishes? Or will you change your major to biology?
%
Are you making all this up as you go along?
%
Are you sure the back door is locked?
%
Artistic ventures highlighted. Rob a museum.
%
Avert misunderstanding by calm, poise, and balance.
%
Avoid gunfire in the bathroom tonight.
%
Avoid reality at all costs.
%
Bank error in your favor. Collect $200.
%
Be careful! Is it classified?
%
Be careful! UGLY strikes 9 out of 10!
%
Be cautious in your daily affairs.
%
Be cheerful while you are alive.
-- Phathotep, 24th Century B.C.
%
Be different: conform.
%
Be free and open and breezy! Enjoy! Things won't get any better so
get used to it.
%
Be security conscious -- National defense is at stake.
%
Beauty and harmony are as necessary to you as the very breath of life.
%
Best of all is never to have been born. Second best is to die soon.
%
Better hope the life-inspector doesn't come around while you have your
life in such a mess.
%
Beware of a dark-haired man with a loud tie.
%
Beware of a tall black man with one blond shoe.
%
Beware of a tall blond man with one black shoe.
%
Beware of Bigfoot!
%
Beware of low-flying butterflies.
%
Beware the one behind you.
%
Blow it out your ear.
%
Break into jail and claim police brutality.
%
Bridge ahead. Pay troll.
%
Caution: breathing may be hazardous to your health.
%
Caution: Keep out of reach of children.
%
Celebrate Hannibal Day this year. Take an elephant to lunch.
%
Change your thoughts and you change your world.
%
Cheer Up! Things are getting worse at a slower rate.
%
Chess tonight.
%
Chicken Little only has to be right once.
%
Chicken Little was right.
%
Cold hands, no gloves.
%
Communicate! It can't make things any worse.
%
Courage is your greatest present need.
%
Day of inquiry. You will be subpoenaed.
%
Do not overtax your powers.
%
Do not sleep in a eucalyptus tree tonight.
%
Do nothing unless you must, and when you must act -- hesitate.
%
Do something unusual today. Pay a bill.
%
Do what comes naturally. Seethe and fume and throw a tantrum.
%
Domestic happiness and faithful friends.
%
Don't feed the bats tonight.
%
Don't get stuck in a closet -- wear yourself out.
%
Don't get to bragging.
%
Don't go surfing in South Dakota for a while.
%
Don't hate yourself in the morning -- sleep till noon.
%
Don't kiss an elephant on the lips today.
%
Don't let your mind wander -- it's too little to be let out alone.
%
Don't look back, the lemmings are gaining on you.
%
Don't look now, but the man in the moon is laughing at you.
%
Don't look now, but there is a multi-legged creature on your shoulder.
%
Don't plan any hasty moves. You'll be evicted soon anyway.
%
Don't read any sky-writing for the next two weeks.
%
Don't read everything you believe.
%
Don't relax! It's only your tension that's holding you together.
%
Don't tell any big lies today. Small ones can be just as effective.
%
Don't worry so loud, your roommate can't think.
%
Don't Worry, Be Happy.
-- Meher Baba
%
Don't worry. Life's too long.
-- Vincent Sardi, Jr.
%
Don't you feel more like you do now than you did when you came in?
%
Don't you wish you had more energy... or less ambition?
%
Everything that you know is wrong, but you can be straightened out.
%
Everything will be just tickety-boo today.
%
Excellent day for putting Slinkies on an escalator.
%
Excellent day to have a rotten day.
%
Excellent time to become a missing person.
%
Executive ability is prominent in your make-up.
%
Exercise caution in your daily affairs.
%
Expect a letter from a friend who will ask a favor of you.
%
Expect the worst, it's the least you can do.
%
Fine day for friends.
So-so day for you.
%
Fine day to work off excess energy. Steal something heavy.
%
Fortune: You will be attacked next Wednesday at 3:15 p.m. by six samurai
sword wielding purple fish glued to Harley-Davidson motorcycles.
Oh, and have a nice day!
-- Bryce Nesbitt '84
%
Future looks spotty. You will spill soup in late evening.
%
Generosity and perfection are your everlasting goals.
%
Give him an evasive answer.
%
Give thought to your reputation. Consider changing name and moving to
a new town.
%
Give your very best today. Heaven knows it's little enough.
%
Go to a movie tonight. Darkness becomes you.
%
Good day for a change of scene. Repaper the bedroom wall.
%
Good day for overcoming obstacles. Try a steeplechase.
%
Good day to deal with people in high places; particularly lonely stewardesses.
%
Good day to let down old friends who need help.
%
Good news from afar can bring you a welcome visitor.
%
Good news. Ten weeks from Friday will be a pretty good day.
%
Good night to spend with family, but avoid arguments with your mate's
new lover.
%
Green light in A.M. for new projects. Red light in P.M. for traffic tickets.
%
Hope that the day after you die is a nice day.
%
If you can read this, you're too close.
%
If you learn one useless thing every day, in a single year you'll learn
365 useless things.
%
If you sow your wild oats, hope for a crop failure.
%
If you stand on your head, you will get footprints in your hair.
%
If you think last Tuesday was a drag, wait till you see what happens tomorrow!
%
If your life was a horse, you'd have to shoot it.
%
In the stairway of life, you'd best take the elevator.
%
Increased knowledge will help you now. Have mate's phone bugged.
%
Is that really YOU that is reading this?
%
Is this really happening?
%
It is so very hard to be an
on-your-own-take-care-of-yourself-because-there-is-no-one-else-to-do-it-for-you
grown-up.
%
It may or may not be worthwhile, but it still has to be done.
%
It was all so different before everything changed.
%
It's a very *__UN*lucky week in which to be took dead.
-- Churchy La Femme
%
It's all in the mind, ya know.
%
It's lucky you're going so slowly, because you're going in the wrong direction.
%
Just because the message may never be received does not mean it is
not worth sending.
%
Just to have it is enough.
%
Keep emotionally active. Cater to your favorite neurosis.
%
Keep it short for pithy sake.
%
Lady Luck brings added income today. Lady friend takes it away tonight.
%
Learn to pause -- or nothing worthwhile can catch up to you.
%
Let me put it this way: today is going to be a learning experience.
%
Life is to you a dashing and bold adventure.
%
"Life, loathe it or ignore it, you can't like it."
-- Marvin, "Hitchhiker's Guide to the Galaxy"
%
Live in a world of your own, but always welcome visitors.
%
Living your life is a task so difficult, it has never been attempted before.
%
Long life is in store for you.
%
Look afar and see the end from the beginning.
%
Love is in the offing. Be affectionate to one who adores you.
%
Make a wish, it might come true.
%
Many changes of mind and mood; do not hesitate too long.
%
Never be led astray onto the path of virtue.
%
Never commit yourself! Let someone else commit you.
%
Never give an inch!
%
Never look up when dragons fly overhead.
%
Never reveal your best argument.
%
Next Friday will not be your lucky day. As a matter of fact, you don't
have a lucky day this year.
%
Of course you have a purpose -- to find a purpose.
%
People are beginning to notice you. Try dressing before you leave the house.
%
Perfect day for scrubbing the floor and other exciting things.
%
Questionable day.
Ask somebody something.
%
Reply hazy, ask again later.
%
Save energy: be apathetic.
%
Ships are safe in harbor, but they were never meant to stay there.
%
Slow day. Practice crawling.
%
Snow Day -- stay home.
%
So this is it. We're going to die.
%
So you're back... about time...
%
Someone is speaking well of you.
%
Someone is speaking well of you.
How unusual!
%
Someone whom you reject today, will reject you tomorrow.
%
Stay away from flying saucers today.
%
Stay away from hurricanes for a while.
%
Stay the curse.
%
That secret you've been guarding, isn't.
%
The time is right to make new friends.
%
The whole world is a tuxedo and you are a pair of brown shoes.
-- George Gobel
%
There is a 20% chance of tomorrow.
%
There is a fly on your nose.
%
There was a phone call for you.
%
There will be big changes for you but you will be happy.
%
Things will be bright in P.M. A cop will shine a light in your face.
%
Think twice before speaking, but don't say "think think click click".
%
This life is yours. Some of it was given to you; the rest, you made yourself.
%
This will be a memorable month -- no matter how hard you try to forget it.
%
Time to be aggressive. Go after a tattooed Virgo.
%
Today is National Existential Ennui Awareness Day.
%
Today is the first day of the rest of the mess.
%
Today is the first day of the rest of your life.
%
Today is the last day of your life so far.
%
Today is the tomorrow you worried about yesterday.
%
Today is what happened to yesterday.
%
Today's weirdness is tomorrow's reason why.
-- Hunter S. Thompson
%
Tomorrow will be cancelled due to lack of interest.
%
Tomorrow, this will be part of the unchangeable past but fortunately,
it can still be changed today.
%
Tomorrow, you can be anywhere.
%
Tonight you will pay the wages of sin; Don't forget to leave a tip.
%
Tonight's the night: Sleep in a eucalyptus tree.
%
Troubled day for virgins over 16 who are beautiful and wealthy and live
in eucalyptus trees.
%
Truth will out this morning. (Which may really mess things up.)
%
Try the Moo Shu Pork. It is especially good today.
%
Try to get all of your posthumous medals in advance.
%
Try to have as good a life as you can under the circumstances.
%
Try to relax and enjoy the crisis.
-- Ashleigh Brilliant
%
Try to value useful qualities in one who loves you.
%
Tuesday After Lunch is the cosmic time of the week.
%
Tuesday is the Wednesday of the rest of your life.
%
What happened last night can happen again.
%
While you recently had your problems on the run, they've regrouped and
are making another attack.
%
Write yourself a threatening letter and pen a defiant reply.
%
You are a bundle of energy, always on the go.
%
You are a fluke of the universe; you have no right to be here.
%
You are a very redundant person, that's what kind of person you are.
%
You are always busy.
%
You are as I am with You.
%
You are capable of planning your future.
%
You are confused; but this is your normal state.
%
You are deeply attached to your friends and acquaintances.
%
You are destined to become the commandant of the fighting men of the
department of transportation.
%
You are dishonest, but never to the point of hurting a friend.
%
You are fairminded, just and loving.
%
You are farsighted, a good planner, an ardent lover, and a faithful friend.
%
You are fighting for survival in your own sweet and gentle way.
%
You are going to have a new love affair.
%
You are magnetic in your bearing.
%
You are not dead yet. But watch for further reports.
%
You are number 6! Who is number one?
%
You are only young once, but you can stay immature indefinitely.
%
You are scrupulously honest, frank, and straightforward. Therefore you
have few friends.
%
You are sick, twisted and perverted. I like that in a person.
%
You are so boring that when I see you my feet go to sleep.
%
You are standing on my toes.
%
You are taking yourself far too seriously.
%
You are the only person to ever get this message.
%
You are wise, witty, and wonderful, but you spend too much time reading
this sort of trash.
%
You attempt things that you do not even plan because of your extreme stupidity.
%
You can create your own opportunities this week. Blackmail a senior executive.
%
You can do very well in speculation where land or anything to do with dirt
is concerned.
%
You can rent this space for only $5 a week.
%
You could live a better life, if you had a better mind and a better body.
%
You definitely intend to start living sometime soon.
%
You dialed 5483.
%
You display the wonderful traits of charm and courtesy.
%
You don't become a failure until you're satisfied with being one.
%
You enjoy the company of other people.
%
You feel a whole lot more like you do now than you did when you used to.
%
You fill a much-needed gap.
%
You get along very well with everyone except animals and people.
%
You had some happiness once, but your parents moved away, and you had to
leave it behind.
%
You have a deep appreciation of the arts and music.
%
You have a deep interest in all that is artistic.
%
You have a reputation for being thoroughly reliable and trustworthy.
A pity that it's totally undeserved.
%
You have a strong appeal for members of the opposite sex.
%
You have a strong appeal for members of your own sex.
%
You have a strong desire for a home and your family interests come first.
%
You have a truly strong individuality.
%
You have a will that can be influenced by all with whom you come in contact.
%
You have an ability to sense and know higher truth.
%
You have an ambitious nature and may make a name for yourself.
%
You have an unusual equipment for success. Be sure to use it properly.
%
You have an unusual magnetic personality. Don't walk too close to
metal objects which are not fastened down.
%
You have an unusual understanding of the problems of human relationships.
%
You have been selected for a secret mission.
%
You have Egyptian flu: you're going to be a mummy.
%
You have had a long-term stimulation relative to business.
%
You have literary talent that you should take pains to develop.
%
You have many friends and very few living enemies.
%
You have no real enemies.
%
You have taken yourself too seriously.
%
You have the body of a 19 year old. Please return it before it gets wrinkled.
%
You have the capacity to learn from mistakes. You'll learn a lot today.
%
You have the power to influence all with whom you come in contact.
%
You learn to write as if to someone else because NEXT YEAR YOU WILL BE
"SOMEONE ELSE."
%
You like to form new friendships and make new acquaintances.
%
You look like a million dollars. All green and wrinkled.
%
You look tired.
%
You love peace.
%
You love your home and want it to be beautiful.
%
You may be gone tomorrow, but that doesn't mean that you weren't here today.
%
You may be infinitely smaller than some things, but you're infinitely
larger than others.
%
You may be recognized soon. Hide.
%
You may get an opportunity for advancement today. Watch it!
%
You may worry about your hair-do today, but tomorrow much peanut butter will
be sold.
%
You need more time; and you probably always will.
%
You need no longer worry about the future. This time tomorrow you'll be dead.
%
You never hesitate to tackle the most difficult problems.
%
You never know how many friends you have until you rent a house on the beach.
%
You now have Asian Flu.
%
You own a dog, but you can only feed a cat.
%
You plan things that you do not even attempt because of your extreme caution.
%
You possess a mind not merely twisted, but actually sprained.
%
You prefer the company of the opposite sex, but are well liked by your own.
%
You recoil from the crude; you tend naturally toward the exquisite.
%
You seek to shield those you love and you like the role of the provider.
%
You shall be rewarded for a dastardly deed.
%
You should emulate your heros, but don't carry it too far. Especially
if they are dead.
%
You should go home.
%
You single-handedly fought your way into this hopeless mess.
%
You teach best what you most need to learn.
%
You too can wear a nose mitten.
%
You two ought to be more careful--your love could drag on for years and years.
%
You will always get the greatest recognition for the job you least like.
%
You will always have good luck in your personal affairs.
%
You will attract cultured and artistic people to your home.
%
You will be a winner today. Pick a fight with a four-year-old.
%
You will be advanced socially, without any special effort on your part.
%
You will be aided greatly by a person whom you thought to be unimportant.
%
You will be attacked by a beast who has the body of a wolf, the tail of
a lion, and the face of Donald Duck.
%
You will be audited by the Internal Revenue Service.
%
You will be awarded a medal for disregarding safety in saving someone.
%
You will be awarded some great honor.
%
You will be awarded the Nobel Peace Prize... posthumously.
%
You will be called upon to help a friend in trouble.
%
You will be divorced within a year.
%
You will be given a post of trust and responsibility.
%
You will be held hostage by a radical group.
%
You will be honored for contributing your time and skill to a worthy cause.
%
You will be imprisoned for contributing your time and skill to a bank robbery.
%
You will be married within a year, and divorced within two.
%
You will be married within a year.
%
You will be misunderstood by everyone.
%
You will be recognized and honored as a community leader.
%
You will be reincarnated as a toad; and you will be much happier.
%
You will be run over by a beer truck.
%
You will be run over by a bus.
%
You will be singled out for promotion in your work.
%
You will be successful in love.
%
You will be surprised by a loud noise.
%
You will be surrounded by luxury.
%
You will be the last person to buy a Chrysler.
%
You will be the victim of a bizarre joke.
%
You will be Told about it Tomorrow. Go Home and Prepare Thyself.
%
You will be traveling and coming into a fortune.
%
You will be winged by an anti-aircraft battery.
%
You will become rich and famous unless you don't.
%
You will contract a rare disease.
%
You will engage in a profitable business activity.
%
You will experience a strong urge to do good; but it will pass.
%
You will feel hungry again in another hour.
%
You will forget that you ever knew me.
%
You will gain money by a fattening action.
%
You will gain money by a speculation or lottery.
%
You will gain money by an illegal action.
%
You will gain money by an immoral action.
%
You will get what you deserve.
%
You will give someone a piece of your mind, which you can ill afford.
%
You will have a long and boring life.
%
You will have a long and unpleasant discussion with your supervisor.
%
You will have domestic happiness and faithful friends.
%
You will have good luck and overcome many hardships.
%
You will have long and healthy life.
%
You will hear good news from one you thought unfriendly to you.
%
You will inherit millions of dollars.
%
You will inherit some money or a small piece of land.
%
You will live a long, healthy, happy life and make bags of money.
%
You will live to see your grandchildren.
%
You will lose your present job and have to become a door to door mayonnaise
salesman.
%
You will meet an important person who will help you advance professionally.
%
You will never know hunger.
%
You will not be elected to public office this year.
%
You will obey or molten silver will be poured into your ears.
%
You will outgrow your usefulness.
%
You will overcome the attacks of jealous associates.
%
You will pass away very quickly.
%
You will pay for your sins. If you have already paid, please disregard
this message.
%
You will pioneer the first Martian colony.
%
You will probably marry after a very brief courtship.
%
You will reach the highest possible point in your business or profession.
%
You will receive a legacy which will place you above want.
%
You will remember something that you should not have forgotten.
%
You will soon forget this.
%
You will soon meet a person who will play an important role in your life.
%
You will step on the night soil of many countries.
%
You will stop at nothing to reach your objective, but only because your
brakes are defective.
%
You will triumph over your enemy.
%
You will visit the Dung Pits of Glive soon.
%
You will win success in whatever calling you adopt.
%
You will wish you hadn't.
%
You work very hard. Don't try to think as well.
%
You worry too much about your job. Stop it. You are not paid enough to worry.
%
You would if you could but you can't so you won't.
%
You'd like to do it instantaneously, but that's too slow.
%
You'll be called to a post requiring ability in handling groups of people.
%
You'll be sorry...
%
You'll feel devilish tonight. Toss dynamite caps under a flamenco dancer's
heel.
%
You'll feel much better once you've given up hope.
%
You'll never be the man your mother was!
%
You'll never see all the places, or read all the books, but fortunately,
they're not all recommended.
%
You'll wish that you had done some of the hard things when they were easier
to do.
%
You're a card which will have to be dealt with.
%
You're almost as happy as you think you are.
%
You're at the end of the road again.
%
You're being followed. Cut out the hanky-panky for a few days.
%
You're currently going through a difficult transition period called "Life."
%
You're definitely on their list. The question to ask next is what list it is.
%
You're growing out of some of your problems, but there are others that
you're growing into.
%
You're not my type. For that matter, you're not even my species!!!
%
You're ugly and your mother dresses you funny.
%
You're working under a slight handicap. You happen to be human.
%
You've been leading a dog's life. Stay off the furniture.
%
Your aim is high and to the right.
%
Your aims are high, and you are capable of much.
%
Your analyst has you mixed up with another patient. Don't believe a
thing he tells you.
%
Your best consolation is the hope that the things you failed to get weren't
really worth having.
%
Your boss climbed the corporate ladder, wrong by wrong.
%
Your boss is a few sandwiches short of a picnic.
%
Your boyfriend takes chocolate from strangers.
%
Your business will assume vast proportions.
%
Your business will go through a period of considerable expansion.
%
Your depth of comprehension may tend to make you lax in worldly ways.
%
Your domestic life may be harmonious.
%
Your fly might be open (but don't check it just now).
%
Your goose is cooked.
(Your current chick is burned up too!)
%
Your heart is pure, and your mind clear, and your soul devout.
%
Your ignorance cramps my conversation.
%
Your life would be very empty if you had nothing to regret.
%
Your love life will be happy and harmonious.
%
Your love life will be... interesting.
%
Your lover will never wish to leave you.
%
Your lucky color has faded.
%
Your lucky number has been disconnected.
%
Your lucky number is 3552664958674928. Watch for it everywhere.
%
Your mode of life will be changed for the better because of good news soon.
%
Your mode of life will be changed for the better because of new developments.
%
Your motives for doing whatever good deed you may have in mind will be
misinterpreted by somebody.
%
Your nature demands love and your happiness depends on it.
%
Your object is to save the world, while still leading a pleasant life.
%
Your own qualities will help prevent your advancement in the world.
%
Your present plans will be successful.
%
Your reasoning is excellent -- it's only your basic assumptions that are wrong.
%
Your reasoning powers are good, and you are a fairly good planner.
%
Your sister swims out to meet troop ships.
%
Your society will be sought by people of taste and refinement.
%
Your step will soil many countries.
%
Your supervisor is thinking about you.
%
Your talents will be recognized and suitably rewarded.
%
Your temporary financial embarrassment will be relieved in a surprising manner.
%
Your true value depends entirely on what you are compared with.
%

1365
deps/fortune/kenm vendored

File diff suppressed because it is too large Load Diff

38122
deps/fortune/showerthoughts vendored

File diff suppressed because it is too large Load Diff

44
deps/manifest.json vendored

@ -0,0 +1,44 @@
{
"acKind": "ImageManifest",
"acVersion": "0.7.1",
"name": "unixvoid.com/lorebot",
"labels": [
{
"name": "version",
"value": "latest"
},
{
"name": "arch",
"value": "amd64"
},
{
"name": "os",
"value": "linux"
}
],
"app": {
"user": "root",
"group": "root",
"exec": [
"/run.sh"
],
"mountPoints": [
{
"name": "redis",
"path": "/redisbackup/",
"readOnly": false
},
{
"name": "auth",
"path": "/.auth",
"readOnly": false
}
]
},
"annotations": [
{
"name": "authors",
"value": "Matthew Faltys <mfaltys@gmail.com>"
}
]
}

4
deps/redis.conf vendored

@ -0,0 +1,4 @@
daemonize yes
dbfilename dump.rdb
dir /redisbackup/
save 30 1

BIN
deps/rootfs.tar.gz vendored

Binary file not shown.

5
deps/run.sh vendored

@ -0,0 +1,5 @@
#!/bin/sh
redis-server /redis.conf
/lorebot $@

8
deps/run_lorebot.sh vendored

@ -0,0 +1,8 @@
#!/bin/bash
sudo docker run \
-d \
-v /home/mfaltys/lorebot-data/redis:/redisbackup:rw \
-v /home/mfaltys/lorebot-data/.auth:/.auth:ro \
--name lorebot \
lorebot

14
go.mod

@ -0,0 +1,14 @@
module git.bitnuke.io/mfaltys/lorebot
go 1.17
require (
github.com/bwmarrin/discordgo v0.24.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/unixvoid/glogger v0.0.0-20160808141529-efa058094480 // indirect
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
gopkg.in/gcfg.v1 v1.2.3 // indirect
gopkg.in/redis.v5 v5.2.9 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)

20
go.sum

@ -0,0 +1,20 @@
github.com/bwmarrin/discordgo v0.24.0 h1:Gw4MYxqHdvhO99A3nXnSLy97z5pmIKHZVJ1JY5ZDPqY=
github.com/bwmarrin/discordgo v0.24.0/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/unixvoid/glogger v0.0.0-20160808141529-efa058094480 h1:v5/8W8Oi7f4DcOSsiJoLGT82Bc5nWFk4YJmu60QDNJw=
github.com/unixvoid/glogger v0.0.0-20160808141529-efa058094480/go.mod h1:K6t28t5XA5wg9q+wm1+Epl41QOvjLnRnavvNUdQ7FmU=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/gcfg.v1 v1.2.3 h1:m8OOJ4ccYHnx2f4gQwpno8nAX5OGOh7RLaaz0pj3Ogs=
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
gopkg.in/redis.v5 v5.2.9 h1:MNZYOLPomQzZMfpN3ZtD1uyJ2IDonTTlxYiV/pEApiw=
gopkg.in/redis.v5 v5.2.9/go.mod h1:6gtv0/+A4iM08kdRfocWYB3bLX2tebpNtfKlFT6H4mY=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=

111
lorebot/botfunc.go

@ -0,0 +1,111 @@
package main
import (
"errors"
"fmt"
"strings"
"time"
"github.com/unixvoid/glogger"
"gopkg.in/redis.v5"
)
func loreQuery(searchTerm string, redisClient *redis.Client) ([]string, error) {
val, err := redisClient.Sort(searchTerm, redis.Sort{Order: "ALPHA"}).Result()
if err != nil {
return nil, errors.New("String not found.")
} else {
return val, nil
}
}
func loreCheck(searchTerm, searchType string, redisClient *redis.Client) (string, error) {
val, err := redisClient.HGet(fmt.Sprintf("%s:%s", searchType, searchTerm), "content").Result()
if err != nil {
return "", errors.New("String not found.")
} else {
return val, nil
}
}
func loreNewString(nick, newString, newType string, redisClient *redis.Client) error {
s := strings.SplitN(newString, " ", 2)
command, content := s[0], []byte(s[1])
stripContent := strings.Replace(fmt.Sprintf("%s", content), "<", "", -1)
stripLinks := strings.Replace(stripContent, ">", "", -1)
// dont allow certain chars
if strings.ContainsAny(command, ";:,.'\"!$%^*()/\\") {
// reject user input, it has unwanted chars
return errors.New("error: entry contains unwanted characters")
}
t := time.Now()
// create a timestamp to use
cdate := t.Format("2006-01-02 15:04:05")
// create the redis hash
_, err := redisClient.HMSet(fmt.Sprintf("%s:%s", newType, command), map[string]string{
"content": stripLinks,
"cdate": cdate,
"owner": nick,
}).Result()
if err != nil {
glogger.Error.Println("error setting redis hash")
return errors.New("error setting redis hash")
}
// add lore to index
err = redisClient.SAdd(fmt.Sprintf("index:%s:added", newType), command).Err()
if err != nil {
glogger.Error.Println("error updating redis index")
return errors.New("error updating redis index")
}
return nil
}
func loreRmString(nick, rmString, rmType string, redisClient *redis.Client) error {
t := time.Now()
// remove redis hash containing lore and metadata
redisClient.Del(fmt.Sprintf("%s:%s", rmType, rmString))
// create a timestamp to use
rmdate := t.Format("2006-01-02 15:04:05")
// create the redis hash
_, err := redisClient.HMSet(fmt.Sprintf("%s:%s", rmType, rmString), map[string]string{
"rmdate": rmdate,
"rmby": nick,
}).Result()
if err != nil {
glogger.Error.Println("error setting redis hash")
return errors.New("error setting redis hash")
}
// add lore to index
redisClient.SAdd(fmt.Sprintf("index:%s:removed", rmType), rmString).Err()
if err != nil {
glogger.Error.Printf("error removing lore from 'index:%s:removed'\n", rmType)
}
// remove lore form added index
redisClient.SRem(fmt.Sprintf("index:%s:added", rmType), rmString).Err()
if err != nil {
glogger.Error.Printf("error removing lore from 'index:%s:added'\n", rmType)
}
return nil
}
func loreAttrQuery(queryString, queryType, queryAttr string, redisClient *redis.Client) (string, error) {
val, err := redisClient.HGet(fmt.Sprintf("%s:%s", queryType, queryAttr), queryString).Result()
if err != nil {
return "", errors.New("String not found.")
} else {
return val, nil
}
}

746
lorebot/lorebot.go

@ -0,0 +1,746 @@
package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"math/rand"
"mime/multipart"
"net/http"
"net/textproto"
"os"
"os/exec"
"os/signal"
"strconv"
"strings"
"syscall"
"time"
"github.com/bwmarrin/discordgo"
"github.com/unixvoid/glogger"
"gopkg.in/gcfg.v1"
"gopkg.in/redis.v5"
)
type Config struct {
Lorebot struct {
Loglevel string
SlackDebug bool
BootstrapDelay time.Duration
AuthFile string
}
Redis struct {
Host string
Password string
}
}
var (
config = Config{}
)
func main() {
// read in config file
readConf()
// initialize the logger with the configured loglevel
initLogger(config.Lorebot.Loglevel)
// read in creds
credentials, _ := ioutil.ReadFile(config.Lorebot.AuthFile)
lines := strings.Split(string(credentials), "\n")
auth := lines[0]
// Create a new Discord session using the provided bot token.
goBot, err := discordgo.New("Bot " + auth)
if err != nil {
fmt.Println("error creating Discord session,", err)
return
}
// Register the msgParser func as a callback for message events.
goBot.AddHandler(msgParser)
// Open a websocket connection to Discord and begin listening.
err = goBot.Open()
if err != nil {
fmt.Println("error opening connection,", err)
return
}
// Wait here until CTRL-C or other term signal is received.
fmt.Println("Bot is now running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
// Cleanly close down the Discord session.
goBot.Close()
}
func readConf() {
// init config file
err := gcfg.ReadFileInto(&config, "config.gcfg")
if err != nil {
panic(fmt.Sprintf("Could not load config.gcfg, error: %s\n", err))
}
}
func initLogger(logLevel string) {
// init logger
if logLevel == "debug" {
glogger.LogInit(os.Stdout, os.Stdout, os.Stdout, os.Stderr)
} else if logLevel == "cluster" {
glogger.LogInit(os.Stdout, os.Stdout, ioutil.Discard, os.Stderr)
} else if logLevel == "info" {
glogger.LogInit(os.Stdout, ioutil.Discard, ioutil.Discard, os.Stderr)
} else {
glogger.LogInit(ioutil.Discard, ioutil.Discard, ioutil.Discard, os.Stderr)
}
}
func initRedisConnection() (*redis.Client, error) {
// init redis connection
redisClient := redis.NewClient(&redis.Options{
Addr: config.Redis.Host,
Password: config.Redis.Password,
DB: 0,
})
_, redisErr := redisClient.Ping().Result()
return redisClient, redisErr
}
func msgParser(s *discordgo.Session, m *discordgo.MessageCreate) {
// exit out if its a blank message or gif/photo
if len(m.Content) == 0 {
return
}
//// // debug message recieved if its not too long
//// glogger.Debug.Printf("length of msg is: %d", len(m.Content))
//// if len(m.Content) <= 150 {
//// glogger.Debug.Printf("Message recieved: %s\n", m.Content)
//// } else {
//// glogger.Debug.Printf("Message too big to print\n")
//// }
// Ignore all messages created by the bot itself
if m.Author.ID == s.State.User.ID {
return
}
comm := fmt.Sprintf("%c", m.Content[0])
//glogger.Debug.Printf("comm var: %s", comm)
if comm == "." {
if strings.Count(m.Content, " ") == 0 {
// no spaces, its a static command
glogger.Debug.Printf("processing static command")
staticCommandHandler(s, m)
} else {
// spaces, its a dynamic command
glogger.Debug.Printf("processing dynamic command")
dynamicCommandHandler(s, m)
}
}
// If the message is "ping" reply with "Pong!"
if m.Content == "ping" {
s.ChannelMessageSend(m.ChannelID, "fuck off bloam")
}
}
//
// static functions
//
func staticCommandHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
// initialize redis connection
redisClient, err := initRedisConnection()
if err != nil {
glogger.Debug.Printf("redis conneciton cannot be made, trying again in %d seconds", config.Lorebot.BootstrapDelay)
time.Sleep(config.Lorebot.BootstrapDelay * time.Second)
redisClient, err = initRedisConnection()
if err != nil {
glogger.Error.Println("redis connection cannot be made.")
}
}
tmpStr := strings.SplitN(m.Content, " ", 2)
command := tmpStr[0]
trimmedPrefix := strings.TrimPrefix(command, ".")
switch trimmedPrefix {
case "help":
helpMsg(s, m)
case "help2":
advancedHelpMsg(s, m)
case "rng":
rngHandler(s, m, redisClient)
case "dubs":
dubsHandler(s, m, redisClient)
case "lunch":
lunchHandler(s, m, redisClient)
case "brb":
brbHandler(s, m, redisClient)
case "roll":
rollHandler(s, m)
case "rr":
rrHandler(s, m)
case "dice":
diceRollHandler(s, m)
case "ceelo":
ceeloRollHandler(s, m)
case "fortune":
fortuneHandler(s, m)
case "kenm":
kenmHandler(s, m)
case "showerthoughts":
showerthoughtsHandler(s, m)
case "listen":
s.ChannelMessageSend(m.ChannelID, "*it's what you hearin*")
case "lorelist":
listHandler(redisClient, s, m, "lore", "added")
case "removedlore":
listHandler(redisClient, s, m, "lore", "removed")
case "commandlist":
listHandler(redisClient, s, m, "command", "added")
case "removedcommands":
listHandler(redisClient, s, m, "command", "removed")
case "lorestatus":
loreStatus(s, m, redisClient)
}
// get that dice handler
if len(m.Content) >= 2 {
if strings.Contains(m.Content, ".d") {
trm := strings.Replace(m.Content, ".d", "", -1)
// check if the rest of the string is an int
num, err := strconv.Atoi(trm)
if err == nil {
//glogger.Debug.Printf("rolling for %d", num)
dHandler(s, m, num)
}
}
}
}
func helpMsg(s *discordgo.Session, m *discordgo.MessageCreate) {
help1 := "I am the lore archival bot, I support the following commands:\n" +
"```" +
".lore: view lore\n" +
".newlore: add new lore\n" +
".rmlore: remove lore\n" +
".lorelist: view lore database\n" +
".lorestatus: view lore DB status\n" +
".roll: checkum\n" +
".rr: its high noon\n" +
".dice: roll a d6\n" +
".ceelo: roll a ceelo hand\n" +
".listen: rip the dawg\n" +
"use '.help2' to see advanced lookup commands." +
"```"
s.ChannelMessageSend(m.ChannelID, help1)
}
func advancedHelpMsg(s *discordgo.Session, m *discordgo.MessageCreate) {
help2 := "```" +
".created view creation timestamp\n" +
".owner: who created the lore\n" +
".removed: view removal timestamp\n" +
".removedby: who removed the lore\n" +
".rek: rek someone\n" +
".rip: f's in the chat\n" +
".summon: summon someone\n" +
".gnu: dont forget your freedoms\n" +
".brb: find Tjance's location" +
"```"
s.ChannelMessageSend(m.ChannelID, help2)
}
func rngHandler(s *discordgo.Session, m *discordgo.MessageCreate, redisClient *redis.Client) {
// aka index:command:added
newType := fmt.Sprintf("index:lore:added")
//command, err := botfunc.Query(newType, redisClient)
command, err := loreQuery(newType, redisClient)
if err != nil {
glogger.Error.Println(err)
println(err)
}
// if the array is empty, exit early
if len(command) <= 0 {
return
}
// pick a random one
rand.Seed(time.Now().UnixNano())
rngLore := fmt.Sprint(command[rand.Intn(len(command))])
glogger.Debug.Printf("rng lore: %s\n", rngLore)
// get lore content
rngContent, err := loreCheck(rngLore, "lore", redisClient)
if err != nil {
glogger.Error.Printf("%v\n", err)
s.ChannelMessageSend(m.ChannelID, "beep boop.. broken bot..")
return
}
glogger.Debug.Printf("rng content: %s\n", rngContent)
rngMsg := fmt.Sprintf("Random lore: `%s`\n%s", rngLore, rngContent)
s.ChannelMessageSend(m.ChannelID, rngMsg)
}
func dubsHandler(s *discordgo.Session, m *discordgo.MessageCreate, redisClient *redis.Client) {
// aka index:command:added
newType := fmt.Sprintf("index:dubs")
command, err := loreQuery(newType, redisClient)
if err != nil {
glogger.Error.Println(err)
}
// if the array is empty, exit early
if len(command) <= 0 {
return
}
// pick a random one
rand.Seed(time.Now().UnixNano())
rngDubs := fmt.Sprint(command[rand.Intn(len(command))])
s.ChannelMessageSend(m.ChannelID, rngDubs)
// roll after we've proccessed dubs
// you already know tho..
//re := regexp.MustCompile(`taylor|swift|2725225`)
//if re.MatchString(rngDubs) {
// rndInt := 1 + rand.Intn(10-1)
// rndStr := fmt.Sprintf("%06d", rand.Int63n(1e6))
// finStr := fmt.Sprintf("%s%d%d", rndStr, rndInt, rndInt)
// rtm.SendMessage(rtm.NewOutgoingMessage(finStr, ev.Channel))
//} else {
// rollhandler(rtm, ev)
//}
rollHandler(s, m)
}
func lunchHandler(s *discordgo.Session, m *discordgo.MessageCreate, redisClient *redis.Client) {
// aka index:command:added
newType := fmt.Sprintf("index:lunch")
command, err := loreQuery(newType, redisClient)
if err != nil {
glogger.Error.Println(err)
}
// if the array is empty, exit early
if len(command) <= 0 {
return
}
// pick a random one
rand.Seed(time.Now().UnixNano())
rngDubs := fmt.Sprint(command[rand.Intn(len(command))])
s.ChannelMessageSend(m.ChannelID, rngDubs)
}
func brbHandler(s *discordgo.Session, m *discordgo.MessageCreate, redisClient *redis.Client) {
// aka index:command:added
newType := fmt.Sprintf("index:brb")
command, err := loreQuery(newType, redisClient)
if err != nil {
glogger.Error.Println(err)
}
// if the array is empty, exit early
if len(command) <= 0 {
return
}
// pick a random one
rand.Seed(time.Now().UnixNano())
rngDubs := fmt.Sprint(command[rand.Intn(len(command))])
s.ChannelMessageSend(m.ChannelID, rngDubs)
}
func rollHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
//fmt.Print(rand.Intn(100))
rngStr := fmt.Sprintf("%08d", rand.Int63n(1e8))
s.ChannelMessageSend(m.ChannelID, rngStr)
}
func rrHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
dice := []string{"*click*", "*BANG*", "*click*", "*click*", "*click*", "*click*"}
rand.Seed(time.Now().UnixNano())
rndStr := dice[rand.Intn(len(dice)-1)]
s.ChannelMessageSend(m.ChannelID, rndStr)
}
func diceRollHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
//fmt.Print(rand.Intn(100))
rand.Seed(time.Now().UnixNano())
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%d", rand.Intn(6)+1))
}
func ceeloRollHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
rand.Seed(time.Now().UnixNano())
// set condition
hand := false
for !hand {
roll0 := rand.Intn(6) + 1
roll1 := rand.Intn(6) + 1
roll2 := rand.Intn(6) + 1
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%d, %d, %d", roll0, roll1, roll2))
// check for pair
if (roll0 == roll1) || (roll0 == roll2) || (roll1 == roll2) {
hand = true
}
a := fmt.Sprintf("%d%d%d", roll0, roll1, roll2)
// check for instant win
if strings.Contains(a, "4") && strings.Contains(a, "5") && strings.Contains(a, "6") {
hand = true
}
// check for instant loss
if strings.Contains(a, "1") && strings.Contains(a, "2") && strings.Contains(a, "3") {
hand = true
}
time.Sleep(1000 * time.Millisecond)
}
}
func fortuneHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
fortune, err := exec.Command("fortune", "-e", "fortunes").CombinedOutput()
if err != nil {
fmt.Printf("%v\n", err)
s.ChannelMessageSend(m.ChannelID, "Fortune command is broken, contact HFIC")
return
}
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%s", fortune))
}
func kenmHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
fortune, err := exec.Command("fortune", "-e", "kenm").CombinedOutput()
if err != nil {
fmt.Printf("%v\n", err)
s.ChannelMessageSend(m.ChannelID, "kenm command is broken, contact HFIC")
return
}
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%s", fortune))
}
func showerthoughtsHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
fortune, err := exec.Command("fortune", "-e", "showerthoughts").CombinedOutput()
if err != nil {
fmt.Printf("%v\n", err)
s.ChannelMessageSend(m.ChannelID, "showerthoughts command is broken, contact HFIC")
return
}
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%s", fortune))
}
func listHandler(redisClient *redis.Client, s *discordgo.Session, m *discordgo.MessageCreate, listType, listAttr string) {
// aka index:command:added
newType := fmt.Sprintf("%s:%s:%s", "index", listType, listAttr)
//command, err := botfunc.Query(newType, redisClient)
command, err := loreQuery(newType, redisClient)
if err != nil {
glogger.Error.Println(err)
println(err)
}
fCommand := strings.Join(command, "\n")
// initialize buffer
bodyBuf := &bytes.Buffer{}
bodyWriter := multipart.NewWriter(bodyBuf)
// create header and body. filename must be set
mh := make(textproto.MIMEHeader)
mh.Set("Content-Type", "application/octet-stream")
mh.Set("Content-Disposition", "form-data; name=\"file\"; filename=\" \"")
// write body with mime header
partWriter, _ := bodyWriter.CreatePart(mh)
io.Copy(partWriter, bytes.NewBufferString(fCommand))
contentType := bodyWriter.FormDataContentType()
bodyWriter.Close()
// set content type to multipart/form-data, required for bitnuke.io
h := make(textproto.MIMEHeader)
h.Set("Content-Type", "multipart/form-data")
bodyWriter.CreatePart(h)
bodyWriter.Close()
// POST to bitnuke.io
resp, err := http.Post("https://bitnuke.io/upload", contentType, bodyBuf)
if err != nil {
println(err)
}
defer resp.Body.Close()
resp_body, err := ioutil.ReadAll(resp.Body)
if err != nil {
println(err)
}
// format response to be link
fResponse := fmt.Sprintf("https://bitnuke.io/%s", resp_body[:])
// print to channel
//rtm.SendMessage(rtm.NewOutgoingMessage(fResponse, ev.Channel))
s.ChannelMessageSend(m.ChannelID, fResponse)
}
func loreStatus(s *discordgo.Session, m *discordgo.MessageCreate, redisClient *redis.Client) {
command, _ := loreQuery("index:lore:added", redisClient)
loreammount := len(command)
status := fmt.Sprintf("the lore db has %d entries", loreammount)
s.ChannelMessageSend(m.ChannelID, status)
}
//
// dynamic functions
//
func dynamicCommandHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
// initialize redis connection
redisClient, err := initRedisConnection()
if err != nil {
glogger.Debug.Printf("redis conneciton cannot be made, trying again in %d seconds", config.Lorebot.BootstrapDelay)
time.Sleep(config.Lorebot.BootstrapDelay * time.Second)
redisClient, err = initRedisConnection()
if err != nil {
glogger.Error.Println("redis connection cannot be made.")
}
}
message := m.Content
if strings.Count(message, " ") < 1 {
glogger.Debug.Println("not proper syntax")
}
// verify syntax
tmpStr := strings.SplitN(message, " ", 2)
command, content := tmpStr[0], tmpStr[1]
trimmedPrefix := strings.TrimPrefix(command, ".")
switch trimmedPrefix {
case "lore":
tmp := strings.SplitN(string(m.Content), " ", 2)
contentHandler(s, m, tmp[1], "lore", redisClient)
case "newlore":
if strings.Contains(content, " ") {
newHandler(s, m, content, "lore", redisClient)
} else {
s.ChannelMessageSend(m.ChannelID, "not proper syntax")
return
}
case "newdubs":
tmp := strings.SplitN(string(m.Content), " ", 2)
newDubsHandler(s, m, tmp[1], redisClient)
case "rmdubs":
tmp := strings.SplitN(string(m.Content), " ", 2)
rmDubsHandler(s, m, tmp[1], redisClient)
case "newlunch":
tmp := strings.SplitN(string(m.Content), " ", 2)
newLunchHandler(s, m, tmp[1], redisClient)
case "rmlunch":
tmp := strings.SplitN(string(m.Content), " ", 2)
rmLunchHandler(s, m, tmp[1], redisClient)
case "newbrb":
tmp := strings.SplitN(string(m.Content), " ", 2)
newBrbHandler(s, m, tmp[1], redisClient)
case "rmbrb":
tmp := strings.SplitN(string(m.Content), " ", 2)
rmBrbHandler(s, m, tmp[1], redisClient)
case "rmlore":
rmHandler(s, m, content, "lore", redisClient)
case "rek":
tmp := strings.SplitN(string(m.Content), " ", 2)
rekHandler(s, m, tmp[1], redisClient)
case "rip":
tmp := strings.SplitN(string(m.Content), " ", 2)
ripHandler(s, m, tmp[1])
case "summon":
tmp := strings.SplitN(string(m.Content), " ", 2)
summonHandler(s, m, tmp[1])
case "gnu":
tmp := strings.SplitN(string(m.Content), " ", 2)
gnuHandler(s, m, tmp[1])
case "created":
attrHandler(s, m, "lore", content, "cdate", redisClient)
case "owner":
attrHandler(s, m, "lore", content, "owner", redisClient)
case "removedby":
attrHandler(s, m, "lore", content, "rmby", redisClient)
case "removed":
attrHandler(s, m, "lore", content, "rmdate", redisClient)
}
}
func contentHandler(s *discordgo.Session, m *discordgo.MessageCreate, message, queryType string, redisClient *redis.Client) {
loreTerm := strings.Replace(message, ".lore", "", -1)
glogger.Debug.Printf("searching for: %s\n", loreTerm)
content, err := loreCheck(loreTerm, queryType, redisClient)
if err == nil {
// lore found, print it
s.ChannelMessageSend(m.ChannelID, content)
} else {
// lore not found, print error
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("lore '%s' not found\n", loreTerm))
}
}
func newHandler(s *discordgo.Session, m *discordgo.MessageCreate, message, newType string, redisClient *redis.Client) {
// get nick from slack api
nick := m.Author.Username
err := loreNewString(nick, message, newType, redisClient)
if err == nil {
s.ChannelMessageSend(m.ChannelID, "entry created")
} else {
s.ChannelMessageSend(m.ChannelID, "entry could not be created")
}
}
func newDubsHandler(s *discordgo.Session, m *discordgo.MessageCreate, newContent string, redisClient *redis.Client) {
// prep content for dubsification
// aka remove the '<' and '>' that slack adds
newContent = strings.Replace(newContent, "<", "", -1)
newContent = strings.Replace(newContent, ">", "", -1)
err := redisClient.SAdd("index:dubs", newContent)
if err != nil {
s.ChannelMessageSend(m.ChannelID, "dubs checked")
} else {
s.ChannelMessageSend(m.ChannelID, "dubs check failed")
}
}
func rmDubsHandler(s *discordgo.Session, m *discordgo.MessageCreate, rmContent string, redisClient *redis.Client) {
// prep content for dubs removal
// aka remove the '<' and '>' that slack adds
rmContent = strings.Replace(rmContent, "<", "", -1)
rmContent = strings.Replace(rmContent, ">", "", -1)
err := redisClient.SRem("index:dubs", rmContent)
if err != nil {
s.ChannelMessageSend(m.ChannelID, "dubs unchecked")
} else {
s.ChannelMessageSend(m.ChannelID, "dubs check failed")
}
}
func newLunchHandler(s *discordgo.Session, m *discordgo.MessageCreate, newContent string, redisClient *redis.Client) {
// prep content for lunchification
// aka remove the '<' and '>' that slack adds
newContent = strings.Replace(newContent, "<", "", -1)
newContent = strings.Replace(newContent, ">", "", -1)
err := redisClient.SAdd("index:lunch", newContent)
if err != nil {
s.ChannelMessageSend(m.ChannelID, "lunch location added")
} else {
s.ChannelMessageSend(m.ChannelID, "lunch location addition failed")
}
}
func rmLunchHandler(s *discordgo.Session, m *discordgo.MessageCreate, rmContent string, redisClient *redis.Client) {
// prep content for lunch removal
// aka remove the '<' and '>' that slack adds
rmContent = strings.Replace(rmContent, "<", "", -1)
rmContent = strings.Replace(rmContent, ">", "", -1)
err := redisClient.SRem("index:lunch", rmContent)
if err != nil {
s.ChannelMessageSend(m.ChannelID, "lunch location removed")
} else {
s.ChannelMessageSend(m.ChannelID, "lunch location removal failed")
}
}
func newBrbHandler(s *discordgo.Session, m *discordgo.MessageCreate, newContent string, redisClient *redis.Client) {
// prep content for brbification
// aka remove the '<' and '>' that slack adds
newContent = strings.Replace(newContent, "<", "", -1)
newContent = strings.Replace(newContent, ">", "", -1)
err := redisClient.SAdd("index:brb", newContent)
if err != nil {
s.ChannelMessageSend(m.ChannelID, "tjancism added")
} else {
s.ChannelMessageSend(m.ChannelID, "tjancism addition failed")
}
}
func rmBrbHandler(s *discordgo.Session, m *discordgo.MessageCreate, rmContent string, redisClient *redis.Client) {
// prep content for brb removal
// aka remove the '<' and '>' that slack adds
rmContent = strings.Replace(rmContent, "<", "", -1)
rmContent = strings.Replace(rmContent, ">", "", -1)
err := redisClient.SRem("index:brb", rmContent)
if err != nil {
s.ChannelMessageSend(m.ChannelID, "tjancism removed")
} else {
s.ChannelMessageSend(m.ChannelID, "tjancism removal failed")
}
}
func rmHandler(s *discordgo.Session, m *discordgo.MessageCreate, message, rmType string, redisClient *redis.Client) {
nick := m.Author.Username
err := loreRmString(nick, message, rmType, redisClient)
if err == nil {
s.ChannelMessageSend(m.ChannelID, "entry removed")
} else {
s.ChannelMessageSend(m.ChannelID, "entry could not be removed")
}
}
func rekHandler(s *discordgo.Session, m *discordgo.MessageCreate, target string, redisClient *redis.Client) {
rektBit, _ := redisClient.SRandMember("index:rekt").Result()
rekFmt := fmt.Sprintf("%s %s", target, rektBit)
s.ChannelMessageSend(m.ChannelID, rekFmt)
}
func ripHandler(s *discordgo.Session, m *discordgo.MessageCreate, target string) {
// create a timestamp to use
t := time.Now()
tstamp := t.Format("01-02-2006")
ripFmt := fmt.Sprintf("here lies %s, disrespected to death %s..", target, tstamp)
s.ChannelMessageSend(m.ChannelID, ripFmt)
}
func summonHandler(s *discordgo.Session, m *discordgo.MessageCreate, target string) {
sumFmt := fmt.Sprintf("つ◕_◕)つ %s つ◕_◕)つ", target)
s.ChannelMessageSend(m.ChannelID, sumFmt)
}
func gnuHandler(s *discordgo.Session, m *discordgo.MessageCreate, target string) {
gnuFmt := fmt.Sprintf("slaps the nonfree software out of %s's hands", target)
s.ChannelMessageSend(m.ChannelID, gnuFmt)
}
func attrHandler(s *discordgo.Session, m *discordgo.MessageCreate, queryType, queryAttr, message string, redisClient *redis.Client) {
query, err := loreAttrQuery(message, queryType, queryAttr, redisClient)
if err == nil {
s.ChannelMessageSend(m.ChannelID, query)
} else {
s.ChannelMessageSend(m.ChannelID, "attribute does not exist")
}
}
func dHandler(s *discordgo.Session, m *discordgo.MessageCreate, num int) {
if (num > 0) && (num < 99999999) {
rand.Seed(time.Now().UnixNano())
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%d", rand.Intn(num)+1))
} else {
s.ChannelMessageSend(m.ChannelID, "na fam, we need a different number. stay lit tho")
}
}

72
readme.md

@ -0,0 +1,72 @@
# Lorebot
This is the bot running over at the sampled slack.
## Commands
### 2 parameters
* `lore`: get a specific lore
* `rip`: rest in piece a target
* `summon`: summon the specified target
* `gnu`: educate the target on freedoms
* `newdubs`: add a new dubs image
* `rmdubs`: remove an existing dubs image
* `created`: lookup when lore was created (some old lore wont have this field)
* `owner`: lookup who created a lore (some old lore wont have this field)
* `removedby`: lookup who removed a lore
* `removed`: lookup when lore was removed
### 1 parameter
* `help`: display help message 1
* `help2`: display help message 2
* `rng`: display random lore with the new rng algorithm
* `depricatedrng`: select random lore with the old rng algorithm
* `roll`: generate a random 8 digit integer
* `d20`: roll a 20 sided die
* `rr`: play russian roulette
* `dice`: roll a 6 sided die
* `dubs`: pick a random 'dubs checkum' image and roll
* `listen`: its what you hearin
* `lorelist`: generate a list of all lore
* `removedlore`: generate a list of removed lore
* `lorestatus`: display the number of active lore
## Building
This project makes use of the `make` command. The following commands are supported.
* `all`: dynamically compiles/builds the bot. outputs binary file to `bin/`
* `run`: runs the bot
* `stat`: statically compiles/builds the bot. outputs binary file to `bin/`
* `docker`: builds a docker image
* `aci`: builds an ACI image
* `test_docker`: tests the docker image
* `test_aci`: tests the ACI image
* `clean`: cleans the project directory of any temp files
## Configuration
This bot takes advantage of the gcfg configuration which follows the INI
syntax.
`config.gcfg`
```
[lorebot]
loglevel = "debug"
slackdebug = false
bootstrapdelay = 1
AuthFile = ".auth"
[redis]
host = "127.0.0.1:6379"
password = ""
```
* `loglevel`: loglevel for the app (debug/info/error)
* `slackdebug`: wheather or not to show slacks API debugging
* `bootstrapdeplay`: number in seconds to delay binding the bot to redis (useful in containers)
* `AuthFile`: name/location of file containing the slack key
* `host`: location of the redis server
* `password`: password of the redis server
`.auth`
```
xoxb-86456556-IJDJksfkejsjdfj
```
this is a key generated by slack for the bot
Loading…
Cancel
Save